﻿using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace 考勤统计
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
            for (int i = 0; i < 31; i++)
            {
                int row = dgv_day.Rows.Add();
            }
            dgv_month.Rows.Add();
            this.dgv_month.Rows[0].Cells[0].Value = "计加班费加班小时";
            this.dgv_month.Rows[0].Cells[1].Value = "工作日实际  加班小时";
            this.dgv_month.Rows[0].Cells[2].Value = "休息日实际  加班小时";
            this.dgv_month.Rows[0].Cells[3].Value = "节假日实际  加班小时";
            this.dgv_month.Rows[0].Cells[4].Value = "存工作日调休 小时";
            this.dgv_month.Rows[0].Cells[5].Value = "存休息日调休 小时";
            this.dgv_month.Rows[0].Cells[6].Value = "存节假日调休 小时";
            this.dgv_month.Rows[0].Cells[7].Value = "实际减调休后工作日加班  小时";
            this.dgv_month.Rows[0].Cells[8].Value = "实际减调休后休息日加班  小时";
            this.dgv_month.Rows[0].Cells[9].Value = "节假日加班  小时";
            this.dgv_month.Rows[0].Cells[10].Value = "二班";
            this.dgv_month.Rows[0].Cells[11].Value = "三班";
            this.dgv_month.Rows[0].Cells[12].Value = "旷工 小时";
            this.dgv_month.Rows[0].Cells[13].Value = "请事假  小时";
            this.dgv_month.Rows[0].Cells[14].Value = "请病假  小时";
            this.dgv_month.Rows[0].Cells[15].Value = "请产假  天数";
            this.dgv_month.Rows[0].Cells[16].Value = "请小产假 天数";
            this.dgv_month.Rows[0].Cells[17].Value = "疫情管控假 小时";
            this.dgv_month.Rows[0].Cells[18].Value = "春假 小时";
            this.dgv_month.Rows[0].Cells[19].Value = "限电调休 小时";
            this.dgv_month.Rows[0].Cells[20].Value = "待料调休 小时";
            this.dgv_month.Rows[0].Cells[21].Value = "未结算待料调休 小时";
            this.dgv_month.Rows[0].Cells[22].Value = "迟到早退次数";
            this.dgv_month.Rows[0].Cells[23].Value = "严重迟到早退次数";
            this.dgv_month.Rows[0].Cells[24].Value = "旷工迟到早退次数";
            this.dgv_month.Rows[0].Cells[25].Value = "上班缺卡次数";
            this.dgv_month.Rows[0].Cells[26].Value = "下班缺卡次数";
            this.dgv_month.Rows[0].Cells[27].Value = "扣全勤    金额";

            string stylepath = System.Environment.CurrentDirectory;

            stylepath = stylepath+ "\\格式文件\\月度报表表头.xlsx";

            using (FileStream fsread_style = File.OpenRead(stylepath))
            {
                workbook_month = new XSSFWorkbook(fsread_style);
                sheet_month = workbook_month.GetSheetAt(0);
            }
        }

        Thread th1=null;

        int excellgetflag = 0;
        bool oneceflag = false;
        bool checkflag = false;
        bool changeflag = false;
        bool jumpflag = false;
        bool timestartflag = false;
        bool searchflag = false;
        bool jbtxok = false;
        bool firstdk = false;
        bool lastdk = false;
        bool tempflag = false;
        bool haveyb = false;
        bool searchok = false;
        bool findflag = false;
        bool txflag = false;
        bool cantgetyb = false;
        bool doublename = false;
        bool search2 = false;

        string daypath = null;
        string dkpath = null;
        string expath = null;
        string outpath = null;
        string foldPath = null;
        string daychangepath = null;

        ISheet sheet_day;
        ISheet sheet_dk;
        ISheet sheet_tx;
        ISheet sheet_jb;
        ISheet sheet_jb1;
        ISheet sheet_month;
        IWorkbook workbook_day = null;
        IWorkbook workbook_dk = null;
        IWorkbook workbook_ex = null;
        IWorkbook workbook_month = null;

        ICellStyle Style = null;
        ICellStyle Style2 = null;
        ICellStyle Style3 = null;
        IFont font1 = null;
        IFont font2 = null;
        IFont font3= null;

        int jbsclie, xmlie, xqlie, bclie, bmlie;
        int dk1lie, dk1jglie, dk2lie, dk2jglie, dk3lie, dk3jglie, dk4lie, dk4jglie;
        int yblie1 = 0, yblie2 = 0;
        int splie;
        int cdsclie, yzcdsclie, ztsclie, kgtslie;
        int sjlie, bjlie, cjlie, xcjlie, dltxlie;
        int xianDianLie;
        int yqjlie,chunjialie;

        int rownum = 0; //dgv行号
        int number = 1; //员工序号
        int m = 0;
        int s = 0;
        int h = 0;
        int dk_row;
        int dk_cell;
        int day_row;
        int startrow = 4;
        int stoprow;

        string dkf, dkl, banci, xingqi, shenpi, bumen, name, dk1jg, dk2jg, yb;
        string searchname;
        string qjsc, jbsc, cdsc, yzcdsc, ztsc, kgts, tx;
        string dkls,namein;
        string title ;
        string time = DateTime.Now.ToString().Substring(0, 7) + "15";
        //string beizhu1 = null;
        //string beizhu2 = null;
        //string beizhu3 = null;
        List<string> txmember = new List<string> { };
        List<string> jbmember1 = new List<string> { };
        List<string> jbmember2 = new List<string> { };
        List<string> txname = new List<string> { };


        #region 文件占用检查
        public static bool IsFileInUse(string fileName)
        {
            bool inUse = true;
            FileStream fs = null;
            try
            {
                fs = new FileStream(fileName, FileMode.Open, FileAccess.Read,
                FileShare.None);
                inUse = false;
            }
            catch
            {
            }
            finally
            {
                if (fs != null)
                    fs.Close();
            }
            return inUse;//true表示正在使用,false没有使用  
        }
        #endregion

        #region 修改设置
        public void set(int hang, int lie, bool bol)
        {
            if (bol == false)
            {
                if (sheet_day.GetRow(hang) == null)
                    sheet_day.CreateRow(hang);
                if (sheet_day.GetRow(hang).GetCell(lie) == null)
                    sheet_day.GetRow(hang).CreateCell(lie);
                sheet_day.GetRow(hang).GetCell(lie).CellStyle = Style;
            }
        }

        public void set2(int hang, int lie, ISheet sheet)
        {
            if (sheet.GetRow(hang) == null)
                sheet.CreateRow(hang);
            if (sheet.GetRow(hang).GetCell(lie) == null)
                sheet.GetRow(hang).CreateCell(lie);
            sheet.GetRow(hang).GetCell(lie).CellStyle = Style2;
        }
        public void set3(int hang, int lie, ISheet sheet)
        {
            if (sheet.GetRow(hang) == null)
                sheet.CreateRow(hang);
            if (sheet.GetRow(hang).GetCell(lie) == null)
                sheet.GetRow(hang).CreateCell(lie);
            sheet.GetRow(hang).GetCell(lie).CellStyle = Style3;
        }

        public void InitFontStyle()
        {
            font1 = workbook_day.CreateFont();
            Style = workbook_day.CreateCellStyle();
            font1.FontName = "黑体";
            font1.FontHeightInPoints = 12;
            Style.FillForegroundColor = HSSFColor.Yellow.Index;                            //填充色
            Style.FillPattern = FillPattern.SolidForeground;                                    //填充格式
            Style.VerticalAlignment = VerticalAlignment.Center;                                 //垂直居中
            Style.WrapText = true;                                                              //自动换行
            Style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;                     //水平居中
            Style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;                            //边框
            Style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
            Style.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
            Style.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
            Style.SetFont(font1);

            font2 = workbook_month.CreateFont();
            Style2 = workbook_month.CreateCellStyle();
            font2.FontName = "宋体";
            font2.FontHeightInPoints = 11;
            Style2.FillForegroundColor = HSSFColor.Yellow.Index;                            //填充色
            Style2.FillPattern = FillPattern.SolidForeground;                                    //填充格式
            Style2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;                            //边框
            Style2.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
            Style2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
            Style2.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
            Style2.SetFont(font2);


            font3 = workbook_ex.CreateFont();
            Style3 = workbook_ex.CreateCellStyle();
            font3.FontName = "宋体";
            font3.FontHeightInPoints = 11;
            Style3.FillForegroundColor = HSSFColor.Yellow.Index;                            //填充色
            Style3.FillPattern = FillPattern.SolidForeground;                                    //填充格式
            Style3.SetFont(font3);
        }
        #endregion

        #region 写操作
        public void writecell(int hang, int lie, double st)
        {
            if (sheet_month.GetRow(hang) == null)
                sheet_month.CreateRow(hang);
            if (sheet_month.GetRow(hang).GetCell(lie) == null)
                sheet_month.GetRow(hang).CreateCell(lie);
            if (st != 0)
            {
                sheet_month.GetRow(hang).GetCell(lie).SetCellValue(st);
            }
            else if (lie == 4 && st == 0)
            {
                sheet_month.GetRow(hang).GetCell(lie).SetCellValue(st);
            }
        }

        public void write(int hang, int lie, string st, bool boll1)
        {
            if (boll1 == false)
            {
                if (sheet_day.GetRow(hang) == null)
                    sheet_day.CreateRow(hang);
                if (sheet_day.GetRow(hang).GetCell(lie) == null)
                    sheet_day.GetRow(hang).CreateCell(lie);
                sheet_day.GetRow(hang).GetCell(lie).SetCellValue(st);
                set(hang, lie, false);
                set(hang, xmlie, false);

            }
        }
        #endregion

        #region 菜单栏
        private void 启动ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (th1 != null && th1.ThreadState == ThreadState.Suspended)
            {                
                启动ToolStripMenuItem.Text = "运行中";
                启动ToolStripMenuItem.Enabled = false;
                th1.Resume();
            }
            else if (excellgetflag != 0 && searchflag == true)
            {
                if (txt_name.Text.Length > 1)
                {
                    启动ToolStripMenuItem.Text = "运行中";
                    启动ToolStripMenuItem.Enabled = false;
                    searchname = txt_name.Text;
                    th1 = new Thread(writedgv);
                    th1.Start();
                }
            }
            else if (excellgetflag == 1 && searchflag == false)
            {
                timestartflag = true;
                th1 = new Thread(writedgv);
                启动ToolStripMenuItem.Text = "运行中";
                启动ToolStripMenuItem.Enabled = false;
                timer1.Enabled = true;
                th1.Start();
            }
        }

        private void 核对模式ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            checkflag = true;
            oneceflag = false;
            searchflag = false;
            if (th1 == null&& excellgetflag==2)
            {
                excellgetflag = 1;
            }
        }

        private void 节假日设定ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            form2.Show();
        }

        private void 自动模式ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            oneceflag = false;
            checkflag = false;
            searchflag = false;
            if (th1 == null && excellgetflag == 2)
            {
                excellgetflag = 1;
            }
        }

        private void 逐个模式ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            oneceflag = true;
            checkflag = false;
            searchflag = false;
            if (th1 == null)
            {
                excellgetflag = 1;
            }
        }

        private void 打开报表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (outpath != "")
            {
                System.Diagnostics.Process.Start("explorer.exe", outpath);
            }
        }

        private void 检索模式ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            searchflag = true;
            oneceflag = false;
            checkflag = false;
            searchok = false;
            if (th1 != null)
            {
                txt_name.Clear();
                txt_class.Clear();
                txt_temp.Clear();
                txt_num.Clear();
                textBox1.Clear();
                for (int i = 0; i < 31; i++)
                {
                    for (int j = 0; j < 12; j++)
                    {
                        dgvwrite(i, j, "", dgv_day, Color.White);
                        //dgv_day.Rows[i].Cells[j].Value = "";
                        //if (dgv_day.Rows[i].Cells[j].Style.BackColor == Color.Yellow)
                        //{
                        //    dgv_day.Rows[i].Cells[j].Style.BackColor = Color.White;
                           
                        //}
                    }
                }
                for (int i = 0; i < 25; i++)
                {
                    dgvwrite(1, i, "", dgv_month, Color.White);
                    //dgv_month.Rows[1].Cells[i].Value = "";
                    //if (dgv_month.Rows[1].Cells[i].Style.BackColor == Color.Yellow && i < 7)
                    //{
                    //    dgv_month.Rows[1].Cells[i].Style.BackColor = Color.White;
                    //}
                }
                if (txt_temp.BackColor == Color.Yellow)
                    txt_temp.BackColor = Color.White;
                if (th1.ThreadState == ThreadState.Suspended)
                    th1.Resume();
                th1.Abort();
                GC.Collect();
                th1 = null;
                启动ToolStripMenuItem.Text = "启动";
                启动ToolStripMenuItem.Enabled = true;
            }
        }

        private void bumencheck()
        {
            if (sheet_jb == null)
            {
                MessageBox.Show("请先选择文件夹！");
                return;
            }
            int jblbrow = 1;
            List<string> jblb = new List<string> { };
            List<Bumen> jblbmis = new List<Bumen>();
            while (sheet_jb.GetRow(jblbrow) != null)
            {
                if (sheet_jb.GetRow(jblbrow).GetCell(0) != null)  //加班类别获取
                {
                    jblb.Add(sheet_jb.GetRow(jblbrow).GetCell(0).ToString().Replace("\n", ""));
                    jblbrow++;
                }
            }
            int row = startrow;
            for (row = startrow; row < sheet_day.LastRowNum + 1; row++)
            {
                string bumenstr = GetDATE(row, bmlie).Replace("\n", "");
                if (bumenstr.Contains("班子") || bumenstr == bumen)
                    continue;
                bumen = bumenstr;
                if (!jblb.Contains(bumen) && bumen != "")
                {

                    jblbmis.Add(new Bumen { bumen = bumen });
                }
            }
            if (jblbmis.Count > 0)
            {
                this.Hide();                
                new Form3(jblbmis).ShowDialog();
                this.Show();
            }
        }
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            System.Environment.Exit(0);
        }

        #endregion

        #region 表格读取
        private void 选择文件夹ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            启动ToolStripMenuItem.Enabled = false;
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.Description = "请选择文件路径";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                foldPath = dialog.SelectedPath;
                Thread threadReadcell = new Thread(readcell);
                threadReadcell.Start();
            }           
        }

        private void readcell()
        {           
            DirectoryInfo theFolder = new DirectoryInfo(foldPath);
            FileInfo[] dirInfo = theFolder.GetFiles();
            //遍历文件夹
            foreach (FileInfo file in dirInfo)
            {
                string path = file.ToString();
                if (path.Contains("每日统计") && (!path.Contains("改")))
                {
                    daypath = foldPath + "\\" + path;
                    // MessageBox.Show(daypath);
                    //System.Diagnostics.Process.Start("explorer.exe", daypath);
                }
                if (path.Contains("打卡时间"))
                    dkpath = foldPath + "\\" + path;
                if (path.Contains("额外统计信息"))
                    expath = foldPath + "\\" + path;
            }

            lab_msg.Text = "表格读取中...";
            Application.DoEvents();

            #region 每日统计表格获取
            while (daypath == null)
            {
                lab_msg.Text = "当前文件夹缺少每日统计表...";
                Application.DoEvents();
                Thread.Sleep(3 * 1000);
                Array.Clear(dirInfo, 0, dirInfo.Length);
                dirInfo = theFolder.GetFiles();
                foreach (FileInfo file in dirInfo)
                {
                    string path = file.ToString();
                    if (path.Contains("每日统计") && (!path.Contains("改")))
                        daypath = foldPath + "\\" + path;
                }

            }
            while (IsFileInUse(daypath) == true)
            {
                lab_msg.Text = "每日统计表被占用，等待关闭...";
                Application.DoEvents();
                Thread.Sleep(3 * 1000);

            }
            using (FileStream fsread_day = File.OpenRead(daypath))
            {
                lab_msg.Text = "每日统计表读取中...";
                Application.DoEvents();
                workbook_day = new XSSFWorkbook(fsread_day);
                sheet_day = workbook_day.GetSheetAt(0);
                fsread_day.Close();
                GC.Collect();
            }
            #endregion

            #region 打卡时间表格获取
            while (dkpath == null)
            {
                lab_msg.Text = "当前文件夹缺少打卡时间表...";
                Application.DoEvents();
                Thread.Sleep(3 * 1000);
                Array.Clear(dirInfo, 0, dirInfo.Length);
                dirInfo = theFolder.GetFiles();
                foreach (FileInfo file in dirInfo)
                {
                    string path = file.ToString();
                    if (path.Contains("打卡时间"))
                        dkpath = foldPath + "\\" + path;
                }

            }
            while (IsFileInUse(dkpath) == true)
            {
                lab_msg.Text = "打卡时间表被占用，等待关闭...";
                Application.DoEvents();
                Thread.Sleep(3 * 1000);

            }
            using (FileStream fsread_dk = File.OpenRead(dkpath))
            {
                lab_msg.Text = "打卡时间表读取中...";
                Application.DoEvents();
                workbook_dk = new XSSFWorkbook(fsread_dk);
                sheet_dk = workbook_dk.GetSheetAt(0);
                fsread_dk.Close();
                GC.Collect();

            }
            #endregion

            #region 额外统计信息表格获取
            while (expath == null)
            {
                lab_msg.Text = "当前文件夹缺少额外统计信息表...";
                Application.DoEvents();
                Thread.Sleep(3 * 1000);
                Array.Clear(dirInfo, 0, dirInfo.Length);
                dirInfo = theFolder.GetFiles();
                foreach (FileInfo file in dirInfo)
                {
                    string path = file.ToString();
                    if (path.Contains("额外统计信息"))
                        expath = foldPath + "\\" + path;
                }

            }
            while (IsFileInUse(expath) == true)
            {
                lab_msg.Text = "额外统计信息表被占用，等待关闭...";
                Application.DoEvents();
                Thread.Sleep(3 * 1000);

            }
            using (FileStream fsread_ex = File.OpenRead(expath))
            {
                lab_msg.Text = "额外统计信息表读取中...";
                Application.DoEvents();
                workbook_ex = new XSSFWorkbook(fsread_ex);
                sheet_jb1 = workbook_ex.GetSheetAt(2);
                sheet_tx = workbook_ex.GetSheetAt(1);
                sheet_jb = workbook_ex.GetSheetAt(0);
                fsread_ex.Close();
                GC.Collect();
            }
            #endregion
            cellget();
            bumencheck();
            lab_msg.Text = "表格读取完成...";
            启动ToolStripMenuItem.Enabled = true;
            excellgetflag = 1;
            Application.DoEvents();
        }

        #endregion

        #region DGV更改情况扫描
        string value = "";
        int change_row = 0;
        int change_cell = 0;
        private void dgv_day_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (dgv_day.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
                value = dgv_day.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
            change_row = e.RowIndex;
            change_cell = e.ColumnIndex;
        }
        #endregion

        #region 表格列号抓取 & 补充表格清单抓取

        public string GetDA(ISheet sheet, int hang, int lie)
        {
            string Date = "";
            if (sheet.GetRow(hang) != null)
            {
                if (sheet.GetRow(hang).GetCell(lie) == null)
                    return "false";
                Date = sheet.GetRow(hang).GetCell(lie).ToString();
                return Date;
            }
            return "false";
        }

        public void cellget()
        {
            if (txt_name.Text .Length>1 && searchflag == false)
            {
                findflag = true;
                namein = txt_name.Text;
            }
            InitFontStyle();
            excellgetflag = 2;            
            int day_cell = 0;
            int jb_row = 1;
            while (sheet_day.GetRow(3).GetCell(day_cell) != null)
            {
                if (sheet_day.GetRow(2).GetCell(day_cell) != null)
                {
                    switch (sheet_day.GetRow(2).GetCell(day_cell).ToString())
                    {
                        case "姓名": xmlie = day_cell; break;
                        case "日期": xqlie = day_cell; break;
                        case "班次": bclie = day_cell; break;
                        case "部门": bmlie = day_cell; break;
                        case var a when a.Contains("上班1"): 
                            { 
                                if (dk1lie == 0) { dk1lie = day_cell; dk1jglie = day_cell + 1; day_cell++; } 
                            } break;
                        case var a when a.Contains("下班1"):
                            {
                                if (dk2lie == 0) { dk2lie = day_cell; dk2jglie = day_cell + 1; day_cell++; }
                            } break;
                        case var a when a.Contains("上班2"):
                            {
                                if (dk3lie == 0) { dk3lie = day_cell; dk3jglie = day_cell + 1; day_cell++; }
                            } break;
                        case var a when a.Contains("下班2"):
                            {
                                if (dk4lie == 0) { dk4lie = day_cell; dk4jglie = day_cell + 1; day_cell++; }
                            } break;
                        case "关联的审批单": { splie = day_cell;} break;
                        case var a when a.StartsWith("迟到时长"): { cdsclie = day_cell; } break;
                        case var a when a.StartsWith("严重迟到时长"): { yzcdsclie = day_cell; } break;
                        case var a when a.StartsWith("早退时长"): { ztsclie = day_cell; } break;
                        case "旷工天数": { kgtslie = day_cell; } break;
                        case "加班总时长": { jbsclie = day_cell; } break;
                        case "二班班次": { yblie1 = day_cell; } break;
                        case "三班班次": { yblie2 = day_cell; } break;
                    }
                }
                switch (sheet_day.GetRow(3).GetCell(day_cell).ToString())
                {
                    case var a when a.Contains("工作日（转加班费）"): { gzjblie = day_cell; } break;
                    case var a when a.Contains("休息日（转加班费）"): { xxjblie = day_cell; } break;
                    case var a when a.Contains("节假日（转加班费）"): { jjjblie = day_cell; } break;
                    case var a when a.Contains("工作日（转调休）"): { gztxlie = day_cell; } break;
                    case var a when a.Contains("休息日（转调休）"): { xxtxlie = day_cell; } break;
                    case var a when a.Contains("节假日（转调休）"): { jjtxlie = day_cell; } break;
                    case var a when a.Contains("事假"): sjlie = day_cell; break;
                    case var a when a.StartsWith("产假"): cjlie = day_cell; break;
                    case var a when a.StartsWith("小产假"): xcjlie = day_cell; break;
                    case var a when a.Contains("疫情管控"): yqjlie = day_cell; break;
                    case var a when a.Contains("春假"): chunjialie = day_cell; break;
                    case var a when a.Contains( "待料调休"): dltxlie = day_cell; break;
                    case var a when a.Contains("限电调休"): xianDianLie = day_cell; break;
                    case var a when a.Contains("病假"): { bjlie = day_cell; } break;
                }
                day_cell++;
            }
            if (yblie1 == 0)
            {
                yblie1 = jjtxlie + 1;
                yblie2 = jjtxlie + 2;
                this.write(3, yblie1, "二班", false);
                this.write(3, yblie2, "三班", false);
            }
            try
            {
                while (GetDA(sheet_jb, jb_row, 3) != "false")
                {
                    txmember.Add(GetDA(sheet_jb, jb_row, 3));
                    jb_row++;
                }
                jb_row = 1;

                while (GetDA(sheet_jb, jb_row, 4) != "false")
                {
                    jbmember1.Add(GetDA(sheet_jb, jb_row, 4));
                    jb_row++;
                }
                jb_row = 1;
                    
                int jb1_row = 1;
                while (GetDA(sheet_jb1,jb1_row, 0) != "false")
                {                      
                    jbmember2.Add(GetDA(sheet_jb1, jb1_row, 0));
                    jb1_row++;
                }                 
                int tx_row = 1;
                while (GetDA(sheet_tx, tx_row, 0) != "false")
                {
                    txname.Add(GetDA(sheet_tx, tx_row, 0));
                    tx_row++;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("额外统计信息读取错误！");
            }
}
        #endregion

        #region 每日具体属性数据获取 & 写出 day_DGV

        public void shuxingget()
        {
            xingqi = GetDATE(day_row, xqlie);
            banci = GetDATE(day_row, bclie);
            shenpi = GetDATE(day_row, splie);
            List<string> str = shenpi.Split(new char[] { '\n', ',' }).ToList();
            foreach (var item in str)
            {
                if (item.Contains("补卡"))
                {
                    shenpi = shenpi.Replace(item, "");
                    if (shenpi.StartsWith(","))
                    {
                        shenpi = shenpi.Substring(1);
                    }
                }
            }
            cdsc = GetDATE(day_row, cdsclie);
            yzcdsc = GetDATE(day_row, yzcdsclie);
            ztsc = GetDATE(day_row, ztsclie);
            jbsc = GetDATE(day_row, jbsclie);
            kgts = GetDATE(day_row, kgtslie);
            dk1jg = dktemp(day_row).Item3;
            dk2jg = dktemp(day_row).Item4;
            dkf = dktemp(day_row).Item1;
            dkl = dktemp(day_row).Item2;
            if (dk1jg != "" && dk1jg != "缺卡")
                firstdk = true;
            if (name.Contains("离职") && (dk2jg == "缺卡"||dk2jg=="请假") && !banci.Contains("休息") && lastdk == false)
            {
                int a=day_row+1;               
                lastdk = true;
                while (name == GetDATE(a, xmlie))
                {
                    if (dktemp(a).Item1 != "")
                        lastdk = false;
                    a++;
                }
            }
            yb = "";
            if (haveyb == true)
            {
                if (GetDATE(day_row, yblie1) != "0" && GetDATE(day_row, yblie1) != "" && yblie1 != 0)
                    yb = "二班";
                if (GetDATE(day_row, yblie2) != "0" && GetDATE(day_row, yblie2) != "" && yblie2 != 0)
                    yb = "三班";
            }
            dgv_day.Rows[rownum].Cells[0].Value = xingqi;
            dgv_day.Rows[rownum].Cells[1].Value = banci;
            dgv_day.Rows[rownum].Cells[2].Value = dkf;
            dgv_day.Rows[rownum].Cells[3].Value = dkl;
            dgv_day.Rows[rownum].Cells[4].Value = shenpi;
            qjsc = "";
            if (GetDATE(day_row, cjlie) != "" && cjlie != 0)
                qjsc = "(产假)" + GetDATE(day_row, cjlie) + "天";
            if (GetDATE(day_row, xcjlie) != "" && xcjlie != 0)
                qjsc = "(小产假)" + GetDATE(day_row, xcjlie) + "天";
            if (GetDATE(day_row, yqjlie) != "" && yqjlie != 0)
                qjsc = "(疫情管控)" + GetDATE(day_row, yqjlie) + "小时";
            if (GetDATE(day_row, chunjialie) != "" && chunjialie != 0)
                qjsc = "(春假)" + GetDATE(day_row, chunjialie) + "小时";
            if (GetDATE(day_row, bjlie) != "" && bjlie != 0)
                qjsc = "(病假)" + GetDATE(day_row, bjlie) + "小时";
            if (GetDATE(day_row, sjlie) != "" && sjlie != 0)
                qjsc = "(事假)" + GetDATE(day_row, sjlie) + "小时";
            if (GetDATE(day_row, dltxlie) != "" && dltxlie != 0)
                qjsc = "(待料调休)" + GetDATE(day_row, dltxlie) + "小时";
            if (GetDATE(day_row, xianDianLie) != "" && xianDianLie != 0)
                qjsc = "(限电调休)" + GetDATE(day_row, xianDianLie) + "小时";
            dgv_day.Rows[rownum].Cells[5].Value = qjsc;
            dgv_day.Rows[rownum].Cells[6].Value = "";
            if (yzcdsc != "0")
                dgv_day.Rows[rownum].Cells[7].Value = yzcdsc;
            else if (cdsc != "0")
                dgv_day.Rows[rownum].Cells[7].Value = cdsc;
            else
                dgv_day.Rows[rownum].Cells[7].Value = "";
            if (ztsc != "0")
                dgv_day.Rows[rownum].Cells[8].Value = ztsc;
            else
                dgv_day.Rows[rownum].Cells[8].Value = "";
            if (kgts != "0")
                dgv_day.Rows[rownum].Cells[9].Value = kgts;
            else
                dgv_day.Rows[rownum].Cells[9].Value = "";
            if (jbsc != "0")
                dgv_day.Rows[rownum].Cells[10].Value = jbsc;
            else
                dgv_day.Rows[rownum].Cells[10].Value = "";
            dgv_day.Rows[rownum].Cells[11].Value = yb;
            Application.DoEvents();
        }
        #endregion

        #region 当月汇总 & 写出 month_DGV
        int month_day = 0;
        int month_row = 4;
        public void writedgvm()
        {
            bool gzrchangeflag = false;
            bool xxrchangeflag = false;
            bool jjrchangeflag = false;
            double gzrjbsp = 0.0;
            double xxrjbsp = 0.0;
            double gzrjb = 0.0;
            double xxrjb = 0.0;
            double jjrjb = 0.0;
            double gzrtx = 0.0;
            double xxrtx = 0.0;
            double jjrtx = 0.0;
            double yb2cs = 0.0;
            double yb3cs = 0.0;
            double kgxs = 0.0;
            double sj = 0.0;
            double bj = 0.0;
            double cj = 0.0;
            double xcj = 0.0;
            int cdcs = 0;
            int yzcdcs = 0;
            int kgcdts = 0;
            int sbqk = 0;
            int xbqk = 0;
            double dltx = 0.0;
            double xianDianTx = 0.0;
            double yqj = 0.0,chunjia=0.0;
            for (int i = 0; i < this.month_day; i++)
            {
                string month_rq = this.strget(i, 0);
                string month_bc = this.strget(i, 1);
                string month_sb = this.strget(i, 2);
                string month_xb = this.strget(i, 3);
                string month_qjsc = this.strget(i, 5);
                double month_tx = this.numberget(i, 6);
                double month_cd = this.numberget(i, 7);
                double month_zt = this.numberget(i, 8);
                double month_kg = this.numberget(i, 9);
                double month_jb = this.numberget(i, 10);
                string month_yb = this.strget(i, 11);
                bool flag = month_qjsc != "";
                if (flag)
                {
                    if (month_qjsc.Contains("疫情"))
                    {
                        month_qjsc = month_qjsc.Remove(0, 6);
                        yqj += double.Parse(month_qjsc.Substring(0, month_qjsc.Length - 2));
                    }
                    if (month_qjsc.Contains("限电调休"))
                    {
                        month_qjsc = month_qjsc.Remove(0, 6);
                        xianDianTx += double.Parse(month_qjsc.Substring(0, month_qjsc.Length - 2));
                    }
                    if (month_qjsc.Contains("春假"))
                    {
                        month_qjsc = month_qjsc.Remove(0, 4);
                        chunjia += double.Parse(month_qjsc.Substring(0, month_qjsc.Length - 2));
                    }
                    bool flag2 = month_qjsc.Contains("事假");
                    if (flag2)
                    {
                        month_qjsc = month_qjsc.Remove(0, 4);
                        sj += double.Parse(month_qjsc.Substring(0, month_qjsc.Length - 2));
                    }
                    else
                    {
                        bool flag3 = month_qjsc.Contains("病假");
                        if (flag3)
                        {
                            month_qjsc = month_qjsc.Remove(0, 4);
                            bj += double.Parse(month_qjsc.Substring(0, month_qjsc.Length - 2));
                        }
                        else
                        {
                            bool flag4 = month_qjsc.Contains("小产假");
                            if (flag4)
                            {
                                month_qjsc = month_qjsc.Remove(0, 5);
                                xcj += double.Parse(month_qjsc.Substring(0, month_qjsc.Length - 1)) * 8.0;
                            }
                            else
                            {
                                bool flag5 = month_qjsc.Contains("产假");
                                if (flag5)
                                {
                                    month_qjsc = month_qjsc.Remove(0, 4);
                                    cj += double.Parse(month_qjsc.Substring(0, month_qjsc.Length - 1));
                                }
                                else
                                {
                                    bool flag6 = month_qjsc.Contains("待料调休");
                                    if (flag6)
                                    {
                                        month_qjsc = month_qjsc.Remove(0, 6);
                                        dltx += double.Parse(month_qjsc.Substring(0, month_qjsc.Length - 2));
                                    }
                                }
                            }
                        }
                    }
                }
                bool flag7 = Form2.jjrday.Count > 0 && Form2.jjrday.Contains(i + 1);
                if (flag7)
                {
                    bool flag8 = month_jb.ToString() != "" && month_jb != 0.0;
                    if (flag8)
                    {
                        jjrjb += month_jb;
                        bool flag9 = month_tx.ToString() != "";
                        if (flag9)
                        {
                            jjrtx += month_tx;
                        }
                    }
                    //bool flag10 = this.dgv_day.Rows[i].Cells[10].Style.BackColor == Color.Yellow;
                    if (changejb)
                    {
                        jjrchangeflag = true;
                    }
                }
                else
                {
                    bool flag11 = month_bc.Contains("休息")&& (Form2.txday.Count == 0 || !Form2.txday.Contains(i + 1));
                    if (flag11)
                    {
                        bool flag12 = month_jb.ToString() != "" && month_jb != 0.0;
                        if (flag12)
                        {
                            bool flag13 = this.jbmember2.Contains(this.name);
                            if (flag13)
                            {
                                for (int j = 0; j < this.jbmember2.Count; j++)
                                {
                                    bool flag14 = this.name == this.jbmember2[j];
                                    if (flag14)
                                    {
                                        bool flag15 = this.sheet_jb1.GetRow(j + 1).GetCell(i + 1) != null;
                                        if (flag15)
                                        {
                                            bool flag16 = this.sheet_jb1.GetRow(j + 1).GetCell(i + 1).ToString() != "" && this.sheet_jb1.GetRow(j + 1).GetCell(i + 1).ToString() != "0";
                                            if (flag16)
                                            {
                                                xxrjbsp += month_jb;
                                            }
                                        }
                                    }
                                }
                            }
                            xxrjb += month_jb;
                            bool flag17 = month_tx.ToString() != "";
                            if (flag17)
                            {
                                xxrtx += month_tx;
                            }
                        }
                        //bool flag18 = this.dgv_day.Rows[i].Cells[10].Style.BackColor == Color.Yellow;
                        if (changejb)
                        {
                            xxrchangeflag = true;
                        }
                    }
                    else
                    {
                        bool flag19 = month_jb.ToString() != "" && month_jb != 0.0;
                        if (flag19)
                        {
                            bool flag20 = this.jbmember2.Contains(this.name);
                            if (flag20)
                            {
                                for (int k = 0; k < this.jbmember2.Count; k++)
                                {
                                    bool flag21 = this.name == this.jbmember2[k];
                                    if (flag21)
                                    {
                                        bool flag22 = this.sheet_jb1.GetRow(k + 1).GetCell(i + 1) != null;
                                        if (flag22)
                                        {
                                            bool flag23 = this.sheet_jb1.GetRow(k + 1).GetCell(i + 1).ToString() != "" && this.sheet_jb1.GetRow(k + 1).GetCell(i + 1).ToString() != "0";
                                            if (flag23)
                                            {
                                                gzrjbsp += month_jb;
                                            }
                                        }
                                    }
                                }
                            }
                            gzrjb += month_jb;
                            bool flag24 = month_tx.ToString() != "";
                            if (flag24)
                            {
                                gzrtx += month_tx;
                            }
                        }
                        //bool flag25 = this.dgv_day.Rows[i].Cells[10].Style.BackColor == Color.Yellow;
                        if (changejb)
                        {
                            gzrchangeflag = true;
                        }
                    }
                }
                bool flag26 = month_yb == "二班";
                if (flag26)
                {
                    yb2cs += 1.0;
                }
                bool flag27 = month_yb == "三班";
                if (flag27)
                {
                    yb3cs += 1.0;
                }
                bool flag28 = month_zt.ToString() != "" && month_zt != 0.0;
                if (flag28)
                {
                    bool flag29 = month_zt > 60.0;
                    if (flag29)
                    {
                        kgcdts++;
                    }
                    else
                    {
                        bool flag30 = month_zt > 30.0;
                        if (flag30)
                        {
                            yzcdcs++;
                        }
                        else
                        {
                            cdcs++;
                        }
                    }
                }
                bool flag31 = month_cd.ToString() != "" && month_cd != 0.0;
                if (flag31)
                {
                    bool flag32 = month_cd > 60.0;
                    if (flag32)
                    {
                        kgcdts++;
                    }
                    else
                    {
                        bool flag33 = month_cd > 30.0;
                        if (flag33)
                        {
                            yzcdcs++;
                        }
                        else
                        {
                            cdcs++;
                        }
                    }
                }
                bool flag34 = month_kg.ToString() != "" && month_kg != 0.0;
                if (flag34)
                {
                    kgxs += 8.0;
                }
                else
                {
                    bool flag35 = month_sb.Contains("缺卡") && month_bc.Contains("班次");
                    if (flag35)
                    {
                        sbqk++;
                    }
                    bool flag36 = month_xb.Contains("缺卡") && month_bc.Contains("班次");
                    if (flag36)
                    {
                        xbqk++;
                    }
                }
            }
            this.dgvwrite(1, 1, gzrjb.ToString(), this.dgv_month);
            this.writecell(this.month_row, 5, gzrjb);
            bool flag37 = gzrchangeflag;
            if (flag37)
            {
                this.set2(this.month_row, 5, this.sheet_month);
                //this.dgv_month.Rows[1].Cells[1].Style.BackColor = Color.Yellow;
            }
            this.dgvwrite(1, 2, xxrjb.ToString(), this.dgv_month);
            this.writecell(this.month_row, 6, xxrjb);
            bool flag38 = xxrchangeflag;
            if (flag38)
            {
                this.set2(this.month_row, 6, this.sheet_month);
                //this.dgv_month.Rows[1].Cells[2].Style.BackColor = Color.Yellow;
            }
            this.dgvwrite(1, 3, jjrjb.ToString(), this.dgv_month);
            this.writecell(this.month_row, 7, jjrjb);
            bool flag39 = jjrchangeflag;
            if (flag39)
            {
                this.set2(this.month_row, 7, this.sheet_month);
                //this.dgv_month.Rows[1].Cells[3].Style.BackColor = Color.Yellow;
            }
            this.dgv_month.Rows[1].Cells[4].Value = gzrtx;
            this.writecell(this.month_row, 8, gzrtx);
            this.dgv_month.Rows[1].Cells[5].Value = xxrtx;
            this.writecell(this.month_row, 9, xxrtx);
            this.dgv_month.Rows[1].Cells[6].Value = jjrtx;
            this.writecell(this.month_row, 10, jjrtx);
            gzrjb -= gzrtx;
            xxrjb -= xxrtx;
            jjrjb -= jjrtx;
            double dltx2 = dltx;
            double undltx = 0.0;

            bool flag41 = dltx < xxrjb;
            if (flag41)
            {
                xxrjb -= dltx;
            }
            else
            {
                dltx -= xxrjb;
                xxrjb = 0.0;
                undltx = dltx;
                //bool flag42 = dltx < gzrjb;
                //if (flag42)
                //{
                //    gzrjb -= dltx;
                //}
                //else
                //{
                //    undltx = dltx - gzrjb;
                //    gzrjb = 0.0;
                //}
            }
            this.sheet_month.GetRow(this.month_row).GetCell(1).SetCellValue(this.name);
            bool flag43 = this.doublename;
            if (flag43)
            {
                this.doublename = false;
                this.set2(this.month_row, 1, this.sheet_month);
            }
            bool flag44 = this.cantgetyb;
            if (flag44)
            {
                this.set2(this.month_row, 1, this.sheet_month);
            }
            this.sheet_month.GetRow(this.month_row).GetCell(2).SetCellValue(this.bumen);
            this.sheet_month.GetRow(this.month_row).GetCell(3).SetCellValue(this.txt_temp.Text);
            bool flag45 = this.txt_temp.BackColor == Color.Yellow;
            if (flag45)
            {
                this.set2(this.month_row, 3, this.sheet_month);
            }
            bool flag46 = this.txt_temp.Text == "计加单";
            if (flag46)
            {
                double jiaban = gzrjb + xxrjb + jjrjb * 3.0;
                this.dgvwrite(1, 0, jiaban.ToString(), this.dgv_month);
                this.writecell(this.month_row, 4, jiaban);
            }
            else
            {
                bool flag47 = this.txt_temp.Text == "计加倍";
                if (flag47)
                {
                    bool flag48 = this.jbmember2.Contains(this.name);
                    if (flag48)
                    {
                        double jiaban2 = gzrjbsp * 1.5 + xxrjbsp * 2.0 + jjrjb  * 3.0;
                        this.dgvwrite(1, 0, jiaban2.ToString(), this.dgv_month);
                        this.writecell(this.month_row, 4, jiaban2);
                    }
                    else
                    {
                        double jiaban3 = gzrjb * 1.5 + xxrjb * 2.0 + jjrjb * 3.0;
                        this.dgvwrite(1, 0, jiaban3.ToString(), this.dgv_month);
                        this.writecell(this.month_row, 4, jiaban3);
                    }
                }
                else
                {
                    bool flag49 = this.txt_temp.Text == "计调休";
                    if (flag49)
                    {
                        double jiaban4 =jjrjb * 3.0;
                        this.dgvwrite(1, 0, jiaban4.ToString(), this.dgv_month);
                        this.writecell(this.month_row, 4, jiaban4);
                    }
                }
            }
            bool flag50 = gzrchangeflag || xxrchangeflag || jjrchangeflag;
            if (flag50)
            {
                this.set2(this.month_row, 4, this.sheet_month);
                //this.dgv_month.Rows[1].Cells[0].Style.BackColor = Color.Yellow;
            }
            this.dgv_month.Rows[1].Cells[7].Value = gzrjb;
            this.writecell(this.month_row, 11, gzrjb);
            this.dgv_month.Rows[1].Cells[8].Value = xxrjb;
            this.writecell(this.month_row, 12, xxrjb);
            this.dgv_month.Rows[1].Cells[9].Value = jjrjb;
            this.writecell(this.month_row, 13, jjrjb);
            this.dgv_month.Rows[1].Cells[10].Value = yb2cs;
            this.writecell(this.month_row, 14, yb2cs);
            this.dgv_month.Rows[1].Cells[11].Value = yb3cs;
            this.writecell(this.month_row, 15, yb3cs);
            this.dgv_month.Rows[1].Cells[12].Value = kgxs;
            this.writecell(this.month_row, 16, kgxs);
            this.dgv_month.Rows[1].Cells[13].Value = sj;
            this.writecell(this.month_row, 17, sj);
            this.dgv_month.Rows[1].Cells[14].Value = bj;
            this.writecell(this.month_row, 18, bj);
            this.dgv_month.Rows[1].Cells[15].Value = cj;
            this.writecell(this.month_row, 19, cj);
            this.dgv_month.Rows[1].Cells[16].Value = xcj;
            this.writecell(this.month_row, 20, xcj);
            this.dgv_month.Rows[1].Cells[17].Value = yqj;
            this.writecell(this.month_row, 21, yqj);
            this.dgv_month.Rows[1].Cells[18].Value = chunjia;
            this.writecell(this.month_row, 22, chunjia);
            this.dgv_month.Rows[1].Cells[19].Value = xianDianTx;
            this.writecell(this.month_row, 23, xianDianTx);
            this.dgv_month.Rows[1].Cells[20].Value = dltx2;
            this.writecell(this.month_row, 24, dltx2);
            this.dgv_month.Rows[1].Cells[21].Value = undltx;
            this.writecell(this.month_row, 25, undltx);
            bool flag51 = undltx > 0.0;
            if (flag51)
            {
                //this.dgv_month.Rows[1].Cells[0].Style.BackColor = Color.Yellow;
                //this.dgv_month.Rows[1].Cells[18].Style.BackColor = Color.Yellow;
                this.set2(this.month_row, 25, this.sheet_month);
            }
            this.dgv_month.Rows[1].Cells[22].Value = cdcs;
            this.writecell(this.month_row, 26, (double)cdcs);
            this.dgv_month.Rows[1].Cells[23].Value = yzcdcs;
            this.writecell(this.month_row, 27, (double)yzcdcs);
            this.dgv_month.Rows[1].Cells[24].Value = kgcdts;
            this.writecell(this.month_row, 28, (double)kgcdts);
            this.dgv_month.Rows[1].Cells[25].Value = sbqk;
            this.writecell(this.month_row, 29, (double)sbqk);
            this.dgv_month.Rows[1].Cells[26].Value = xbqk;
            this.writecell(this.month_row, 30, (double)xbqk);
            this.month_row++;
        }
        #endregion

        #region 员工属性读取
        public void yuangongget()
        {
            txt_temp.Text = "";
            int jb_row = 1;
            txt_num.Text = number.ToString();
            txt_name.Text = name;
            txt_class.Text = bumen;
            while (sheet_jb.GetRow(jb_row).GetCell(0) != null)  //加班类别获取
            {
                if (sheet_jb.GetRow(jb_row).GetCell(0).ToString() == bumen)
                {
                    txt_temp.Text = sheet_jb.GetRow(jb_row).GetCell(1).ToString();
                    tempflag = true;
                    break;
                }
                jb_row++;
                if (bumen == "" || bumen.Contains("班子成员"))
                {
                    tempflag = true;
                    break;
                }
                else if (jb_row == sheet_jb.LastRowNum+1)
                {
                    tempflag = true;
                    //MessageBox.Show("未找到" + bumen + "的加班类别！");
                    break;
                }

            }
            if (txmember.Contains(name.Replace("（离职）", "")))
            {
                txt_temp.BackColor = Color.Yellow;
                txt_temp.Text = "计调休";
            }
            if (jbmember1.Contains(name.Replace("（离职）", "")) || jbmember2.Contains(name.Replace("（离职）", "")))
            {
                txt_temp.BackColor = Color.Yellow;
                txt_temp.Text = "计加倍";
            }

        }
        #endregion

        #region 申报调休验证

        int txrows =0;

        public void txget()
        {          
            if (rownum == 0)
            {
                for (int i = 0; i < txname.Count ; i++)
                {
                    if (name == txname[i])
                    {
                        txrows = i+1;
                    }
                }
            }
            if (txrows != 0)
            {
                if (sheet_tx.GetRow(txrows) != null)
                {
                    if (sheet_tx.GetRow(txrows).GetCell(rownum + 1) != null)
                    {
                        if (sheet_tx.GetRow(txrows).GetCell(rownum + 1).ToString() != "")
                        {
                            double b = 0;
                            string a = sheet_tx.GetRow(txrows).GetCell(rownum + 1).ToString();
                            if (double.TryParse(a, out b))
                            {
                                if (jbsc == "")
                                    jbsc = "0";
                                if (double.Parse(jbsc) >= b)
                                    dgv_day.Rows[rownum].Cells[6].Value = a;
                                else
                                {
                                    txflag = true;
                                    a = jbsc;
                                    dgv_day.Rows[rownum].Cells[6].Value = a;
                                    //dgv_day.Rows[rownum].Cells[6].Style.BackColor = Color.Yellow;
                                    set3(txrows, rownum + 1, sheet_tx);
                                }
                                textBox1.AppendText(string.Format("{0:D2}", (rownum + 1)) + "号  :  申报调休  " + a + " 小时\r\n");
                                //beizhu3 = beizhu3 + (rownum + 1) + "号，";
                                changeflag = true;
                            }
                        }
                    }
                }

            }
        }
        #endregion

        #region 线程挂起处理
        public void monthdel()
        {
            tempflag = false;
            //try
            {
                if (jumpflag == false && searchok == true)
                {
                    this.writedgvm();
                }
                if (name == namein)
                {
                    changeflag = false;
                    启动ToolStripMenuItem.Enabled = true;
                    启动ToolStripMenuItem.Text = "继续";
                    namein = "";
                    th1.Suspend();                    
                }
                if (oneceflag == true || (checkflag == true && changeflag == true) || (name == searchname))
                {
                    if (searchflag == true)
                        lab_msg.Text = "搜索完成...";
                    if (searchflag == true)
                    {
                        //启动ToolStripMenuItem.Enabled = false;
                        启动ToolStripMenuItem.Text = "继续";
                        //while (searchname == name && searchname.Length > 1)
                        //{
                        //    searchname = txt_name.Text;
                        //    System.Threading.Thread.Sleep(2000);
                        //}
                        启动ToolStripMenuItem.Enabled = true;
                        th1.Suspend();
                        day_row = startrow;
                        dk_row = 3;
                        number = 0;
                        searchok = false;
                    }
                    else
                    {
                        changeflag = false;
                        启动ToolStripMenuItem.Enabled = true;
                        启动ToolStripMenuItem.Text = "继续";
                        th1.Suspend();
                    }
                    if (change_cell != 0 && change_row != 0)
                    {
                        if (dgv_day.Rows[change_row].Cells[change_cell].Value == null && value != "")
                        {
                            writedgvm();
                            启动ToolStripMenuItem.Enabled = true;
                            启动ToolStripMenuItem.Text = "继续";
                            th1.Suspend();
                        }

                        else if (dgv_day.Rows[change_row].Cells[change_cell].Value.ToString() != value)
                        {
                            writedgvm();
                            启动ToolStripMenuItem.Enabled = true;
                            启动ToolStripMenuItem.Text = "继续";
                            th1.Suspend();

                        }
                        change_row = 0;
                        change_cell = 0;
                        value = "";
                    }
                }
            }
            //catch (Exception e)
            //{
            //    MessageBox.Show(name + "当月统计异常！");
            //}
            if (searchflag == true && day_row == stoprow - 1 && searchname != name)
            {
                MessageBox.Show("请检查名字是否正确！");
            }
            //searchname = txt_name.Text;
            month_day = rownum;
            firstdk = false;
            lastdk = false;
            cantgetyb = false;
            rownum = 0;
            txrows = 0;
            this.dkrowcellget();
            number++;
            jumpflag = false;
            textBox1.Clear();
            for (int i = 0; i < 25; i++)
            {
                dgv_month.Rows[1].Cells[i].Value = "";
                //if (dgv_month.Rows[1].Cells[i].Style.BackColor == Color.Yellow && i < 7)
                //{
                //    dgv_month.Rows[1].Cells[i].Style.BackColor = Color.White;
                //}
            }
            if (txt_temp.BackColor == Color.Yellow)
                txt_temp.BackColor = Color.White;
        }

        public void dkrowcellget()
        {
            this.dk_row = 0;
            this.dk_cell = 0;
            while (this.sheet_dk.GetRow(this.dk_row).GetCell(0) != null)
            {
                bool flag = this.sheet_dk.GetRow(this.dk_row).GetCell(0).ToString() != "姓名";
                if (!flag)
                {
                    while (this.sheet_dk.GetRow(this.dk_row).GetCell(this.dk_cell) != null)
                    {
                        string temp = this.sheet_dk.GetRow(this.dk_row).GetCell(this.dk_cell).ToString();
                        bool flag2 = temp.Contains("Id");
                        if (flag2)
                        {
                            this.dk_cell++;
                            break;
                        }
                        this.dk_cell++;
                    }
                    this.dk_row++;
                    break;
                }
                this.dk_row++;
            }
        }
        #endregion

        List<string> xm = new List<string> { };

        #region 线程1
        private List<string> jjrday = new List<string>();
        private List<string> txday = new List<string>();
        public void writedgv()
        {
            this.txflag = false;
            this.stoprow = this.sheet_day.LastRowNum + 1;
            this.xm.Clear();
            this.day_row = this.startrow;
            while (this.day_row < this.stoprow)
            {
                this.name = this.GetDATE(this.day_row, this.xmlie);
                bool flag = this.GetDATE(this.day_row + 1, this.xmlie) != this.name && !this.name.Contains("离职");
                if (flag)
                {
                    this.xm.Add(this.name);
                }
                this.day_row++;
            }
            this.rownum = 0;
            this.number = 1;
            this.dkrowcellget();
            this.month_day = 0;
            this.month_row = 4;
            this.title = this.GetDATE(0, 0).ToString().Remove(0, 10) + "考勤报表";
            this.sheet_month.GetRow(0).GetCell(0).SetCellValue(this.title);
            this.sheet_month.GetRow(1).GetCell(0).SetCellValue(this.time);
            this.day_row = this.startrow;
            string findname = searchname;
            while (this.day_row < this.stoprow)
            {
                string name = this.GetDATE(this.day_row, this.xmlie);
                if (name != this.name|| rownum > 31)
                {
                    this.name = name;
                    this.rownum = 0;
                    this.bumen = this.GetDATE(this.day_row, this.bmlie);
                    this.yuangongget();
                    for (int i = 0; i < 32; i++)
                    {
                        for (int j = 0; j < 12; j++)
                        {
                            //bool flag5 = this.dgv_day.Rows[this.rownum].Cells[i].Style.BackColor == Color.Yellow;
                            //if (flag5)
                            //{
                            //    this.dgv_day.Rows[this.rownum].Cells[i].Style.BackColor = Color.White;
                            //}
                            this.dgv_day.Rows[i].Cells[j].Value = "";
                        }
                    }
                }
                bool flag2 = this.findflag;
                if (flag2)
                {
                    bool flag3 = this.namein == this.name;
                    if (flag3)
                    {
                        this.findflag = false;
                    }
                }

                bool flag6 = (this.searchflag && this.searchname == this.name) || (!this.searchflag && !this.findflag);
                if (flag6)
                {
                    bool flag7 = this.rownum == 0 && !this.searchflag;
                    if (flag7)
                    {
                        this.lab_msg.Text = this.name + "处理中...";
                    }
                    bool flag8 = this.rownum == 0 && this.searchflag;
                    if (flag8)
                    {
                        this.lab_msg.Text = "搜索中...";
                    }
                    this.searchok = true;
                    bool flag10 = this.bumen.Contains("总经办") || this.name == "张福伦" || this.name == "冉娅梅" || this.name == "岳相军" || this.bumen.Contains("班子成员");
                    if (flag10)
                    {
                        this.jumpflag = true;
                    }
                    else
                    {
                        this.shuxingget();
                        try
                        {
                            this.dktest(this.day_row);
                            this.kgtest(this.day_row);
                            this.jbtest(this.day_row);
                            this.ybtemp(this.day_row);
                            this.txget();
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(this.name + this.xingqi + "异常！\r" + e.ToString());
                        }
                        Application.DoEvents();
                    }
                }
                this.dk_cell++;
                this.rownum++;
                bool flag12 = this.GetDATE(this.day_row + 1, this.xmlie) != this.name;
                if (flag12)
                {
                    bool flag13 = this.name.Contains("离职") && this.xm.Contains(this.name.Substring(0, this.name.Length - 4));
                    if (flag13)
                    {
                        this.doublename = true;
                    }
                    this.monthdel();
                    changejb = false;
                }
                this.day_row++;
            }
            bool flag14 = !this.searchflag;
            if (flag14)
            {
                this.creatcell();
            }
            this.启动ToolStripMenuItem.Text = "启动";
            this.启动ToolStripMenuItem.Enabled = true;
            this.txt_name.Clear();
            this.txt_class.Clear();
            this.txt_temp.Clear();
            this.txt_num.Clear();
            this.检索模式ToolStripMenuItem.Enabled = true;
        }
        #endregion

        #region 报表输出
        public void creatcell()
        {
            outpath = foldPath + "\\" + title + ".xlsx";
            daychangepath = daypath.Substring(0, daypath.Length - 5) + "改.xlsx";
            for (int i = 0; i < 31; i++)
            {
                for (int j = 0; j < 12; j++)
                {
                    dgv_day.Rows[i].Cells[j].Value = "";
                }
            }
            if (txflag == true)
            {
                if (File.Exists(expath))
                {
                    while (IsFileInUse(expath) == true)
                    {
                        Thread.Sleep(3 * 1000);
                    }
                    File.Delete(expath);
                }
                using (FileStream fsread = File.OpenWrite(expath))
                {
                    workbook_ex.Write(fsread);
                    fsread.Close();
                }
                txflag = false;
            }
            if (File.Exists(daychangepath))
            {
                while (IsFileInUse(daychangepath) == true)
                {
                    lab_msg.Text = "每日表改被占用！等待关闭...";
                    Thread.Sleep(3 * 1000);
                }
                lab_msg.Text = "每日表改已存在！正在替换...";
                File.Delete(daychangepath);
            }
            lab_msg.Text = "正在生每日表改...";
            using (FileStream fsread = File.OpenWrite(daychangepath))
            {
                workbook_day.Write(fsread);
                fsread.Close();
            }
            lab_msg.Text = "每日表改写出成功...";
            if (File.Exists(outpath))
            {
                while (IsFileInUse(outpath) == true)
                {
                    lab_msg.Text = "考勤报表被占用！等待关闭...";
                    Thread.Sleep(3 * 1000);
                }
                lab_msg.Text = "考勤报表已存在！正在替换...";
                File.Delete(outpath);
            }
            lab_msg.Text = "正在生成考勤报表...";
            using (FileStream fsread = File.OpenWrite(outpath))
            {
                workbook_month.Write(fsread);
                fsread.Close();
            }

            lab_msg.Text = "考勤报表写出成功...";
            timestartflag = false;
            m = 0;
            s = 0;
            h = 0;

            //daypath = null;
            //dkpath = null;
            //expath = null;
            //foldPath = null;
        }
        #endregion

        #region 获取数据以及处理

        #region 表格只取数字
        public double numberget(int a, int b)
        {            
            double result=0;
            string str;
            if (dgv_day.Rows[a].Cells[b].Value != null)
            {
                str = dgv_day.Rows[a].Cells[b].Value.ToString();
                str=System.Text.RegularExpressions.Regex.Replace(str,@"\s", "");
                if (str != "")
                {
                    result = double.Parse(str);
                }

            }
            return result;
        }
        #endregion

        #region 表格取字符串
        public string strget(int a, int b)
        {
            string str = "";
            if (dgv_day.Rows[a].Cells[b].Value != null)
            {
                if (dgv_day.Rows[a].Cells[b].Value.ToString() != "")
                    str = dgv_day.Rows[a].Cells[b].Value.ToString();
            }
            return str;
        }
        #endregion

        #region 数据获取

        public string GetDATE(int hang, int lie)
        {
            string Date = "";
            if (sheet_day.GetRow(hang) != null)
            {
                if (sheet_day.GetRow(hang).GetCell(lie) == null)
                    return Date;
                Date = sheet_day.GetRow(hang).GetCell(lie).ToString();
            }
            return Date;
        }
        public Tuple<string, string, string, string, string> datetemp(int hang)
        {
            string date4 = GetDATE(hang, xmlie);                //名字    
            string date2 = GetDATE(hang, xqlie);                //星期
            string date1 = GetDATE(hang, bclie);                //班次    
            string date3 = GetDATE(hang, splie);               //审批
            string date5 = "";

            date5 = GetDATE(hang, jbsclie);                  //加班时长
            if (date5 == "")
                date5 = "0";

            Tuple<string, string, string, string, string> dateresult = new Tuple<string, string, string, string, string>
                (date1, date2, date3, date4, date5); //班次 星期 审批 名字 jbsc gzr xxr
            return dateresult;
        }
        private int gztxlie;

        // Token: 0x04000034 RID: 52
        private int xxtxlie;

        // Token: 0x04000035 RID: 53
        private int jjtxlie;
        public bool Istx(int hang)
        {
            bool flag = this.GetDATE(hang, this.gztxlie) != "";
            bool result;
            if (flag)
            {
                result = true;
            }
            else
            {
                bool flag2 = this.GetDATE(hang, this.xxtxlie) != "";
                if (flag2)
                {
                    result = true;
                }
                else
                {
                    bool flag3 = this.GetDATE(hang, this.jjtxlie) != "";
                    result = flag3;
                }
            }
            return result;
        }
        public bool Isjjr(List<string> jjrday, string xingqi)
        {
            foreach (string item in jjrday)
            {
                bool flag = xingqi.Contains(item);
                if (flag)
                {
                    return true;
                }
            }
            return false;
        }
        #endregion

        #region 夜班打卡获取
        public Tuple<string, string> mondayget()
        {
            bool flag = this.name != this.sheet_dk.GetRow(this.dk_row).GetCell(0).ToString();
            if (flag)
            {
                this.dk_row = 0;
                while (this.sheet_dk.GetRow(this.dk_row).GetCell(0).ToString() != this.name)
                {
                    this.dk_row++;
                }
            }
            string date1 = "";
            string date2 = "";
            if (this.sheet_dk.GetRow(this.dk_row).GetCell(this.dk_cell + 1) != null)
            {
                string dk = this.sheet_dk.GetRow(this.dk_row).GetCell(this.dk_cell + 1).ToString();
                string[] a = dk.Split(new char[]
                {
                '\n'
                });

                bool flag2 = dk.Contains("外勤");
                if (flag2)
                {
                    dk = dk.Replace("外勤", "");
                }
                if (dk.Length > 28)
                {
                    if (timetemp(a[2]).Item1 < 10 && timetemp(a[3]).Item1 > 17)
                    {
                        date1 = a[2];
                        date2 = "正常";
                    }
                    else if (timetemp(a[1]).Item1 < 10 && timetemp(a[2]).Item1 > 17)
                    {
                        date1 = a[1];
                        date2 = "正常";
                    }
                    else if (timetemp(a[0]).Item1 < 10 && timetemp(a[1]).Item1 > 17)
                    {
                        date1 = a[0];
                        date2 = "正常";
                    }
                    else if (timetemp(a[3]).Item1 < 10)
                    {
                        date1 = a[3];
                        date2 = "正常";
                    }
                }
                else if (dk.Length > 20)
                {
                    if (timetemp(a[1]).Item1 < 10 && timetemp(a[2]).Item1 > 17)
                    {
                        date1 = a[1];
                        date2 = "正常";
                    }
                    else if (timetemp(a[0]).Item1 < 10 && timetemp(a[1]).Item1 > 17)
                    {
                        date1 = a[0];
                        date2 = "正常";
                    }
                    else if (timetemp(a[2]).Item1 < 10)
                    {
                        date1 = a[2];
                        date2 = "正常";
                    }
                }
                else if (dk.Length > 12)
                {
                    if (timetemp(a[0]).Item1 < 10 && timetemp(a[1]).Item1 > 17)
                    {
                        date1 = a[0];
                        date2 = "正常";
                    }
                    else if (timetemp(a[1]).Item1 < 10)
                    {
                        date1 = a[1];
                        date2 = "正常";
                    }
                }
                else if (dk.Length > 1)
                {
                    if (timetemp(a[0]).Item1 < 10)
                    {
                        date1 = a[0];
                        date2 = "正常";
                    }
                }
                if (date2 == "")
                {
                    dk = this.sheet_dk.GetRow(this.dk_row).GetCell(this.dk_cell).ToString();
                    a = dk.Split(new char[]
                    {
                '\n'
                    });
                    if (a[a.Length - 1] != "" && timetemp(a[a.Length - 1]).Item1 < 5)
                    {
                        date1 = a[a.Length - 1];
                        date2 = "正常";
                    }
                }
            }
            Tuple<string, string> result = new Tuple<string, string>
                (date1, date2);
            return result;
        }
        public Tuple<string, string> sbget()
        {
            bool flag = this.name != this.sheet_dk.GetRow(this.dk_row).GetCell(0).ToString();
            if (flag)
            {
                this.dk_row = 0;
                while (this.sheet_dk.GetRow(this.dk_row).GetCell(0).ToString() != this.name)
                {
                    this.dk_row++;
                }
            }
            string dk = this.sheet_dk.GetRow(this.dk_row).GetCell(this.dk_cell).ToString();
            string[] a = dk.Split(new char[]
            {
                '\n'
            });
            string date1 = "";
            string date2 = "";
            if (dk.Length > 28)
            {
                if (timetemp(a[0]).Item1 > 16)
                {
                    date1 = a[0];
                    date2 = "正常";
                }
                else if (timetemp(a[1]).Item1 > 16)
                {
                    date1 = a[1];
                    date2 = "正常";
                }
                else if (timetemp(a[2]).Item1 > 16)
                {
                    date1 = a[2];
                    date2 = "正常";
                }
                else if (timetemp(a[3]).Item1 > 16)
                {
                    date1 = a[3];
                    date2 = "正常";
                }
            }
            else if (dk.Length > 20)
            {
                if (timetemp(a[0]).Item1 > 16)
                {
                    date1 = a[0];
                    date2 = "正常";
                }
                else if (timetemp(a[1]).Item1 > 16)
                {
                    date1 = a[1];
                    date2 = "正常";
                }
                else if (timetemp(a[2]).Item1 > 16)
                {
                    date1 = a[2];
                    date2 = "正常";
                }
            }
            else if (dk.Length > 12)
            {
                if (timetemp(a[0]).Item1 > 16)
                {
                    date1 = a[0];
                    date2 = "正常";
                }
                else if (timetemp(a[1]).Item1 > 16)
                {
                    date1 = a[1];
                    date2 = "正常";
                }
            }
            else if (dk.Length > 1)
            {
                if (timetemp(a[0]).Item1 > 16)
                {
                    date1 = a[0];
                    date2 = "正常";
                }
            }
            Tuple<string, string> result = new Tuple<string, string>
                (date1, date2);
            return result;
        }
        #endregion

        #region 获取打卡数据
        public Tuple<string, string, string, string, string, string, string> dktemp(int hang)
        {
            string date1 = GetDATE(hang, dk1lie);        //dk1  dkf
            string date2 = GetDATE(hang, dk1jglie);        //dk1jg
            string date3 = GetDATE(hang, dk2lie);        //dk2  
            string date4 = GetDATE(hang, dk2jglie);       //dk2jg
            string date5 = GetDATE(hang, dk3lie);         //dk3
            string date6 = GetDATE(hang, dk3jglie);       //dk3jg
            string date7 = GetDATE(hang, dk4lie);         //dk4
            string date8 = GetDATE(hang, dk4jglie);       //dk4jg
            string date9 = "";                        //dkl
            if (date7 != "")
                date9 = date7;
            else if (date5 != "")
                date9 = date5;
            else if (date3 != "")
                date9 = date3;

            Tuple<string, string, string, string, string, string, string> dkresult = new Tuple<string, string, string, string, string, string, string>
                (date1, date9, date2, date4, date3, date5, date7);
            return dkresult;
        }
        #endregion

        #region 审批数据截取1  
        public Tuple<string, string, string> sptemp1(string spstr1)
        {
                string[] a = spstr1.Split(new char[] { '\n', ',', '，' });
                string sp1 = a[0];                                          //审批单1
                string sp2 = "";                                            //审批单2
                string sp3 = "";                                            //审批单3
                if (spstr1.Length > 40)
                {
                    sp2 = a[1];
                    if (spstr1.Length > 80)
                    {
                        sp3 = a[2];
                    }
                }
                Tuple<string, string, string> spcs = new Tuple<string, string, string>(sp1, sp2, sp3);
                return spcs;

        }
        #endregion

        #region 审批数据截取2  
        public Tuple<string, string, string, string, string, string, string> sptemp2(string spstr2)
        {
            try
            {
                string[] a = sptemp1(spstr2).Item1.Split(new char[] { ' ' });
                string[] b = a[1].Split(new char[] { '到' });
                string a1 = b[0];                                           //审批单1  开始时间
                string a2 = a[2];                                           //审批单1  结束时间
                string b1 = "";                                             //审批单2  开始时间
                string b2 = "";                                             //审批单2  结束时间
                string c1 = "";                                             //审批单3  开始时间
                string c2 = "";                                             //审批单3  结束时间
                if (sptemp1(spstr2).Item2 != "")
                {
                    string[] c = sptemp1(spstr2).Item2.Split(new char[] { ' ' });
                    string[] d = c[1].Split(new char[] { '到' });
                    b1 = d[0];
                    b2 = c[2];
                    if (sptemp1(spstr2).Item3 != "")
                    {
                        string[] e = sptemp1(spstr2).Item3.Split(new char[] { ' ' });
                        string[] f = c[1].Split(new char[] { '到' });
                        c1 = f[0];
                        c2 = e[2];
                    }
                }
                Tuple<string, string, string, string, string, string, string> spdate = new Tuple<string, string, string, string, string, string, string>
                    (a1, a2, b1, b2, c1, c2, a[3].Replace("小时", ""));
                return spdate;
            }
            catch (Exception ex)
            {
                return null;
            }

        }
        #endregion

        #region 时间截取
        public Tuple<double, double> timetemp(string timestr)
        {
            if (timestr.Contains("次日"))
                timestr=timestr.Replace("次日", "");
            bool flag2 = timestr.Contains("外勤");
            if (flag2)
            {
                timestr = timestr.Replace("外勤", "");
            }
            string[] timespl = timestr.Split(new char[] { ':' });
            double timespl1 = int.Parse(timespl[0]);                     //小时
            double timespl2 = int.Parse(timespl[1]);                     //分钟

            Tuple<double, double> timedate = new Tuple<double, double>(timespl1, timespl2);
            return timedate;

        }
        #endregion


        #endregion
        bool changejb = false;
        public delegate void invokehandler();
        public void dgvwrite(int r, int c, string str,DataGridView dgv,Color color)
        {
            dgv.Invoke(new invokehandler(delegate () {
                dgv.Rows[r].Cells[c].Value = str;
                if ((c == 10 && dgv == dgv_day))
                {
                    changejb = true;
                    //dgv.Rows[r].Cells[c].Style.BackColor = color;
                }

            }));
        }
        public void dgvwrite(int r, int c, string str, DataGridView dgv)
        {
            dgv.Invoke(new invokehandler(delegate () {
                dgv.Rows[r].Cells[c].Value = str;
            }));
        }

        #region 主要验证函数

        #region 打卡验证
        public void dktest(int i)
        {
            bool flag = this.dk1jg == "缺卡" && this.dk2jg != "缺卡";
            if (flag)
            {
                this.dgv_day.Rows[this.rownum].Cells[2].Value = "缺卡";
            }
            bool flag2 = this.dk2jg == "缺卡" && this.dk1jg != "缺卡";
            if (flag2)
            {
                if (banci.Contains("晚白班"))
                {
                    string jg = this.mondayget().Item2;
                    bool flag17 = jg != "";
                    if (flag17)
                    {
                        string dk = this.mondayget().Item1;
                        this.dgv_day.Rows[this.rownum].Cells[3].Value = "次日 " + dk;
                        //this.dgv_day.Rows[this.rownum].Cells[3].Style.BackColor = Color.Yellow;
                        this.textBox1.AppendText(string.Concat(new string[]
                        {
                                string.Format("{0:D2}", this.rownum + 1),
                                "号  :  下班 ",
                                this.dkl,
                                "改为 次日 ",
                                dk,
                                "\r\n"
                        }));
                        this.dkl = "次日 " + dk;
                        this.write(i, this.dk2lie, this.dkl, this.searchflag);
                        this.dk2jg = jg;
                        this.write(i, this.dk2jglie, this.dk2jg, this.searchflag);
                        this.changeflag = true;
                    }
                    else
                    {
                        this.dgv_day.Rows[this.rownum].Cells[3].Value = "缺卡";
                    }
                }
                else
                {
                    this.dgv_day.Rows[this.rownum].Cells[3].Value = "缺卡";
                }
            }
            bool flag3 = this.dk2jg == "缺卡" && this.dk1jg == "缺卡" && !this.banci.Contains("不在考勤组");
            if (flag3)
            {
                this.dgv_day.Rows[this.rownum].Cells[2].Value = "旷工";
                this.dgv_day.Rows[this.rownum].Cells[3].Value = "旷工";
            }
            bool flag4 = this.banci.Contains("休息");
            if (flag4)
            {
                bool flag5 = false;
                string shp = this.sptemp1(this.shenpi).Item1;
                string shp2 = this.sptemp1(this.shenpi).Item2;
                string shp3 = this.sptemp1(this.shenpi).Item3;
                if (shp.Contains("加班"))
                {
                    string[] a = shp.Split('到');
                    if (a[0].Contains("17:") || a[0].Contains("18:") || a[0].Contains("19:") || a[0].Contains("20:") || a[0].Contains("21:") || a[0].Contains("22:") || a[0].Contains("23:") )
                    {
                        if (a[1].Contains("00:") || a[1].Contains("01:") || a[1].Contains("02:") || a[1].Contains("03:") || a[1].Contains("04:") || a[1].Contains("05:") || a[1].Contains("06:") || a[1].Contains("07:") || a[1].Contains("08:") ||
                            a[1].Contains("09:") || a[1].Contains("10:") || a[1].Contains("11:") || a[1].Contains("12:"))
                        {
                            string spsc = this.sptemp2(shp).Item7;
                            if (double.Parse(spsc) > 4.5)
                            {
                                flag5 = true;
                            }
                        }
                    }
                }
                if (shp2.Contains("加班"))
                {
                    string[] a = shp2.Split('到');
                    if (a[0].Contains("17:") || a[0].Contains("18:") || a[0].Contains("19:") || a[0].Contains("20:") || a[0].Contains("21:") || a[0].Contains("22:") || a[0].Contains("23:"))
                    {
                        if (a[1].Contains("00:") || a[1].Contains("01:") || a[1].Contains("02:") || a[1].Contains("03:") || a[1].Contains("04:") || a[1].Contains("05:") || a[1].Contains("06:") || a[1].Contains("07:") || a[1].Contains("08:") ||
                            a[1].Contains("09:") || a[1].Contains("10:") || a[1].Contains("11:") || a[1].Contains("12:"))
                        {
                            string spsc = this.sptemp2(shp2).Item7;
                            if (double.Parse(spsc) > 4.5)
                            {
                                flag5 = true;
                            }
                        }
                    }
                }
                if (shp3.Contains("加班"))
                {
                    string[] a = shp3.Split('到');
                    if (a[0].Contains("17:") || a[0].Contains("18:") || a[0].Contains("19:") || a[0].Contains("20:") || a[0].Contains("21:") || a[0].Contains("22:") || a[0].Contains("23:"))
                        {
                            if (a[1].Contains("00:") || a[1].Contains("01:") || a[1].Contains("02:") || a[1].Contains("03:") || a[1].Contains("04:") || a[1].Contains("05:") || a[1].Contains("06:") || a[1].Contains("07:") || a[1].Contains("08:") ||
                                a[1].Contains("09:") || a[1].Contains("10:") || a[1].Contains("11:") || a[1].Contains("12:"))
                            {
                                string spsc = this.sptemp2(shp3).Item7;
                                if (double.Parse(spsc) > 4.5)
                                {
                                    flag5 = true;
                                }
                            }
                    }
                }
                if (flag5)
                {
                    bool flag6 = this.dkf != "";
                    if (flag6)
                    {
                        bool flag7 = this.timetemp(this.dkf).Item1 <= 16.0;
                        if (flag7)
                        {
                            bool flag8 = this.dktemp(i).Item5 != "" && this.timetemp(this.dktemp(i).Item5).Item1 > 16.0;
                            if (flag8)
                            {
                                this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  上班 " + this.dkf);
                                this.dkf = this.dktemp(i).Item5;
                                this.write(i, this.dk1lie, this.dkf, this.searchflag);
                                this.write(i, this.dk1jglie, "正常", this.searchflag);
                                this.dgv_day.Rows[this.rownum].Cells[2].Value = this.dkf;
                                //this.dgv_day.Rows[this.rownum].Cells[2].Style.BackColor = Color.Yellow;
                                this.textBox1.AppendText(" 改为 " + this.dkf + "\r\n");
                                this.dk1jg = "正常";
                            }
                            else
                            {
                                bool flag9 = this.dktemp(i).Item6 != "" && this.timetemp(this.dktemp(i).Item6).Item1 > 16.0;
                                if (flag9)
                                {
                                    this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  上班 " + this.dkf);
                                    this.dkf = this.dktemp(i).Item6;
                                    this.write(i, this.dk1lie, this.dkf, this.searchflag);
                                    this.write(i, this.dk1jglie, "正常", this.searchflag);
                                    this.dgv_day.Rows[this.rownum].Cells[2].Value = this.dkf;
                                    //this.dgv_day.Rows[this.rownum].Cells[2].Style.BackColor = Color.Yellow;
                                    this.textBox1.AppendText(" 改为 " + this.dkf + "\r\n");
                                    this.dk1jg = "正常";
                                }
                                else
                                {
                                    bool flag10 = this.dktemp(i).Item7 != "" && this.timetemp(this.dktemp(i).Item7).Item1 > 16.0;
                                    if (flag10)
                                    {
                                        this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  上班 " + this.dkf);
                                        this.dkf = this.dktemp(i).Item7;
                                        this.write(i, this.dk1lie, this.dkf, this.searchflag);
                                        this.write(i, this.dk1jglie, "正常", this.searchflag);
                                        this.dgv_day.Rows[this.rownum].Cells[2].Value = this.dkf;
                                        //this.dgv_day.Rows[this.rownum].Cells[2].Style.BackColor = Color.Yellow;
                                        this.textBox1.AppendText(" 改为 " + this.dkf + "\r\n");
                                        this.dk1jg = "正常";
                                    }
                                    else
                                    {
                                        string sb = this.sbget().Item1;
                                        this.textBox1.AppendText(string.Concat(new string[]
                                        {
                                            string.Format("{0:D2}", this.rownum + 1),
                                            "号  :  上班 ",
                                            this.dkf,
                                            "改为 ",
                                            sb,
                                            "\r\n"
                                        }));
                                        this.dgv_day.Rows[this.rownum].Cells[2].Value = sb;
                                        //this.dgv_day.Rows[this.rownum].Cells[2].Style.BackColor = Color.Yellow;
                                        this.dkf = sb;
                                        this.write(i, this.dk1lie, this.dkf, this.searchflag);
                                        this.dk1jg = this.sbget().Item2;
                                        this.write(i, this.dk1jglie, this.dk1jg, this.searchflag);
                                        this.changeflag = true;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        string sb2 = this.sbget().Item1;
                        this.textBox1.AppendText(string.Concat(new string[]
                        {
                            string.Format("{0:D2}", this.rownum + 1),
                            "号  :  上班 ",
                            this.dkf,
                            "改为 ",
                            sb2,
                            "\r\n"
                        }));
                        this.dgv_day.Rows[this.rownum].Cells[2].Value = sb2;
                        //this.dgv_day.Rows[this.rownum].Cells[2].Style.BackColor = Color.Yellow;
                        this.dkf = sb2;
                        this.write(i, this.dk1lie, this.dkf, this.searchflag);
                        this.dk1jg = this.sbget().Item2;
                        this.write(i, this.dk1jglie, this.dk1jg, this.searchflag);
                        this.changeflag = true;
                    }
                    bool flag11 = this.dk1jg.Contains("补卡审批通过") && this.dkf.Contains("08:");
                    if (flag11)
                    {
                        string dkfp = "";
                        bool flag12 = this.dkl != "";
                        if (flag12)
                        {
                            bool flag13 = this.dktemp(i).Item5 != "" && this.timetemp(this.dktemp(i).Item5).Item1 > 17.0;
                            if (flag13)
                            {
                                dkfp = this.dktemp(i).Item5;
                            }
                            else
                            {
                                bool flag14 = this.dktemp(i).Item6 != "" && this.timetemp(this.dktemp(i).Item6).Item1 > 17.0;
                                if (flag14)
                                {
                                    dkfp = this.dktemp(i).Item6;
                                }
                                else
                                {
                                    bool flag15 = this.dktemp(i).Item7 != "" && this.timetemp(this.dktemp(i).Item7).Item1 > 17.0;
                                    if (flag15)
                                    {
                                        dkfp = this.dktemp(i).Item7;
                                    }
                                }
                            }
                            bool flag16 = dkfp == "";
                            if (flag16)
                            {
                                this.write(i, this.dk1jglie, "缺卡", this.searchflag);
                                this.dgv_day.Rows[this.rownum].Cells[2].Value = "缺卡";
                                //this.dgv_day.Rows[this.rownum].Cells[2].Style.BackColor = Color.Yellow;
                                this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  上班 " + this.dkf + " 改为 缺卡\r\n");
                                this.dk1jg = "缺卡";
                            }
                            else
                            {
                                this.write(i, this.dk1lie, dkfp, this.searchflag);
                                this.write(i, this.dk1jglie, "正常", this.searchflag);
                                this.dgv_day.Rows[this.rownum].Cells[2].Value = dkfp;
                                //this.dgv_day.Rows[this.rownum].Cells[2].Style.BackColor = Color.Yellow;
                                this.textBox1.AppendText(string.Concat(new string[]
                                {
                                    string.Format("{0:D2}", this.rownum + 1),
                                    "号  :  上班 ",
                                    this.dkf,
                                    " 改为 ",
                                    dkfp,
                                    "\r\n"
                                }));
                                this.dk1jg = "正常";
                            }
                        }
                        else
                        {
                            this.write(i, this.dk1jglie, "缺卡", this.searchflag);
                            this.dgv_day.Rows[this.rownum].Cells[2].Value = "缺卡";
                            //this.dgv_day.Rows[this.rownum].Cells[2].Style.BackColor = Color.Yellow;
                            this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  上班 " + this.dkf + " 改为 缺卡 \r\n");
                            this.dk1jg = "缺卡";
                            dkfp = "";
                        }
                        this.dgv_day.Rows[this.rownum].Cells[3].Value = "次日 " + this.dkf;
                        //this.dgv_day.Rows[this.rownum].Cells[3].Style.BackColor = Color.Yellow;
                        this.textBox1.AppendText(string.Concat(new string[]
                        {
                            string.Format("{0:D2}", this.rownum + 1),
                            "号  :  下班 ",
                            this.dkl,
                            " 改为 次日 ",
                            this.dkf,
                            "\r\n"
                        }));
                        this.changeflag = true;
                        this.dkl = "次日 " + this.dkf;
                        this.write(i, this.dk2lie, this.dkl, this.searchflag);
                        this.write(i, this.dk2jglie, "正常", this.searchflag);
                        this.dkf = dkfp;
                        this.dk2jg = "正常";
                    }
                    else
                    {
                        string jg = this.mondayget().Item2;
                        bool flag17 = jg != "";
                        if (flag17)
                        {
                            if (!dkl.Contains("次日"))
                            {
                                string dk = this.mondayget().Item1;
                                this.dgv_day.Rows[this.rownum].Cells[3].Value = "次日 " + dk;
                                //this.dgv_day.Rows[this.rownum].Cells[3].Style.BackColor = Color.Yellow;
                                this.textBox1.AppendText(string.Concat(new string[]
                                {
                                string.Format("{0:D2}", this.rownum + 1),
                                "号  :  下班 ",
                                this.dkl,
                                "改为 次日 ",
                                dk,
                                "\r\n"
                                }));
                                this.dkl = "次日 " + dk;
                                this.write(i, this.dk2lie, this.dkl, this.searchflag);
                                this.dk2jg = jg;
                                this.write(i, this.dk2jglie, this.dk2jg, this.searchflag);
                                this.changeflag = true;
                            }
                        }
                        else
                        {
                            this.dgv_day.Rows[this.rownum].Cells[3].Value = "缺卡";
                            this.write(i, this.dk2jglie, "缺卡", this.searchflag);
                            //this.dgv_day.Rows[this.rownum].Cells[3].Style.BackColor = Color.Yellow;
                            this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  下班 " + this.dkl + " 改为 缺卡\r\n");
                            this.dkl = "";
                            this.dk2jg = "缺卡";
                            this.changeflag = true;
                        }
                    }
                }
            }
            bool flag18 = this.dk1jg != "" && this.dk2jg == "" && this.banci != "休息";
            if (flag18)
            {
                this.dk2jg = "缺卡";
                this.dgv_day.Rows[this.rownum].Cells[3].Value = "缺卡";
                //this.dgv_day.Rows[this.rownum].Cells[3].Style.BackColor = Color.Yellow;
                this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  下班缺卡\r\n");
                this.changeflag = true;
            }
            bool flag19 = this.dk1jg == "" && this.dk2jg != "" && this.banci != "休息";
            if (flag19)
            {
                this.dk1jg = "缺卡";
                this.dgv_day.Rows[this.rownum].Cells[2].Value = "缺卡";
                //this.dgv_day.Rows[this.rownum].Cells[2].Style.BackColor = Color.Yellow;
                this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  上班缺卡\r\n");
                this.changeflag = true;
            }
            double time = 0.0;
            bool flag20 = this.shenpi.Contains("假") && (!this.shenpi.Contains("16") || !this.shenpi.Contains("8") || !this.shenpi.Contains("天"));
            if (flag20)
            {
                bool flag21 = (this.dk1jg == "外出" || this.dk1jg == "请假") && this.dk2jg != "外出" && this.dk2jg != "请假";
                if (flag21)
                {
                    bool flag22 = this.dkf == "";
                    if (flag22)
                    {
                        this.dk1jg += " 缺卡";
                        this.write(i, this.dk1jglie, this.dk1jg, this.searchflag);
                        this.dgv_day.Rows[this.rownum].Cells[2].Value = this.dk1jg;
                        //this.dgv_day.Rows[this.rownum].Cells[2].Style.BackColor = Color.Yellow;
                        this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  " + this.dk1jg + "\r\n");
                        this.changeflag = true;
                    }
                    else
                    {
                        bool flag23 = this.shenpi.Contains("假") || this.shenpi.Contains("调休") || this.shenpi.Contains("外出");
                        if (flag23)
                        {
                            string shp = this.sptemp1(this.shenpi).Item1;
                            string shp2 = this.sptemp1(this.shenpi).Item2;
                            string shp3 = this.sptemp1(this.shenpi).Item3;
                            double sbkh = this.timetemp(this.dkf).Item1;
                            double sbkm = this.timetemp(this.dkf).Item2;
                            double t = 0.0;
                            double t2 = 0.0;
                            bool flag24 = shp.Contains("假") || shp.Contains("调休") || shp.Contains("外出");
                            if (flag24)
                            {
                                double sph = this.timetemp(this.sptemp2(this.shenpi).Item2).Item1;
                                double spm = this.timetemp(this.sptemp2(this.shenpi).Item2).Item2;
                                bool flag25 = shp.Contains("12:");
                                if (flag25)
                                {
                                    sph = 13.0;
                                    spm = 0.0;
                                    bool flag26 = this.bumen.Contains("制造一课") || this.bumen.Contains("SMT") || this.bumen.Contains("IPQC");
                                    if (flag26)
                                    {
                                        sph = 12.0;
                                        spm = 30.0;
                                    }
                                }
                                t = (sbkh - sph) * 60.0 + (sbkm - spm);
                            }
                            bool flag27 = shp2.Contains("假") || shp2.Contains("调休") || shp2.Contains("外出");
                            if (flag27)
                            {
                                double sph2 = this.timetemp(this.sptemp2(this.shenpi).Item4).Item1;
                                double spm2 = this.timetemp(this.sptemp2(this.shenpi).Item4).Item2;
                                bool flag28 = shp2.Contains("12:");
                                if (flag28)
                                {
                                    sph2 = 13.0;
                                    spm2 = 0.0;
                                    bool flag29 = this.bumen.Contains("制造一课")||this.bumen.Contains("SMT");
                                    if (flag29)
                                    {
                                        sph2 = 12.0;
                                        spm2 = 30.0;
                                    }
                                }
                                t2 = (sbkh - sph2) * 60.0 + (sbkm - spm2);
                            }
                            time = t;
                            bool flag30 = t2 < t && t2 != 0.0;
                            if (flag30)
                            {
                                time = t2;
                            }
                        }
                        else
                        {
                            this.write(i, this.xmlie, this.name, this.searchflag);
                            this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  " + this.dk1jg + " 无审批 \r\n");
                            MessageBox.Show(string.Concat(new object[]
                            {
                                this.rownum + 1,
                                "号  :  ",
                                this.dk1jg,
                                " 无审批 "
                            }));
                            this.changeflag = true;
                        }
                    }
                }
                bool flag31 = (this.dk2jg == "外出" || this.dk2jg == "请假") && this.dk1jg != "外出" && this.dk1jg != "请假";
                if (flag31)
                {
                    bool flag32 = this.dkl == "";
                    if (flag32)
                    {
                        this.dk2jg += " 缺卡";
                        this.write(i, this.dk2jglie, this.dk2jg, this.searchflag);
                        this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  " + this.dk2jg + "\r\n");
                        this.dgv_day.Rows[this.rownum].Cells[3].Value = this.dk2jg;
                        //this.dgv_day.Rows[this.rownum].Cells[3].Style.BackColor = Color.Yellow;
                        this.changeflag = true;
                    }
                    else
                    {
                        bool flag33 = this.shenpi.Contains("假") || this.shenpi.Contains("调休") || this.shenpi.Contains("外出");
                        if (flag33)
                        {
                            bool flag34 = this.dkl.Contains("次日");
                            if (flag34)
                            {
                                this.dkls = this.dkl.Substring(3, 5);
                            }
                            else
                            {
                                this.dkls = this.dkl;
                            }
                            double xbkh = this.timetemp(this.dkls).Item1;
                            double xbkm = this.timetemp(this.dkls).Item2;
                            string shp4 = this.sptemp1(this.shenpi).Item1;
                            string shp5 = this.sptemp1(this.shenpi).Item2;
                            string shp6 = this.sptemp1(this.shenpi).Item3;
                            double t3 = 0.0;
                            double t4 = 0.0;
                            bool flag35 = shp4.Contains("假") || shp4.Contains("调休") || shp4.Contains("外出");
                            if (flag35)
                            {
                                double sph3 = this.timetemp(this.sptemp2(this.shenpi).Item1).Item1;
                                double spm3 = this.timetemp(this.sptemp2(this.shenpi).Item1).Item2;
                                bool flag36 = shp4.Contains("13:") || shp4.Contains("12:");
                                if (flag36)
                                {
                                    sph3 = 12.0;
                                    spm3 = 0.0;
                                }
                                t3 = (sph3 - xbkh) * 60.0 + (spm3 - xbkm);
                            }
                            bool flag37 = shp5.Contains("假") || shp5.Contains("调休") || shp5.Contains("外出");
                            if (flag37)
                            {
                                double sph4 = this.timetemp(this.sptemp2(this.shenpi).Item3).Item1;
                                double spm4 = this.timetemp(this.sptemp2(this.shenpi).Item3).Item2;
                                bool flag38 = shp5.Contains("13:") || shp5.Contains("12:");
                                if (flag38)
                                {
                                    sph4 = 12.0;
                                    spm4 = 0.0;
                                }
                                t4 = (sph4 - xbkh) * 60.0 + (spm4 - xbkm);
                            }
                            time = t3;
                            bool flag39 = t4 < t3 && t4 != 0.0;
                            if (flag39)
                            {
                                time = t4;
                            }
                        }
                        else
                        {
                            bool flag40 = !this.dkl.Contains("次日");
                            if (flag40)
                            {
                                this.write(i, this.xmlie, this.name, this.searchflag);
                                this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  " + this.dk2jg + " 无审批\r\n");
                                MessageBox.Show(string.Concat(new object[]
                                {
                                    this.rownum + 1,
                                    "号  :  ",
                                    this.dk1jg,
                                    " 无审批 "
                                }));
                                this.changeflag = true;
                            }
                        }
                    }
                }
                bool flag41 = time > 10.0;
                if (flag41)
                {
                    bool flag42 = (this.dk1jg == "外出" || this.dk1jg == "请假") && this.dk2jg != "外出" && this.dk2jg != "请假";
                    if (flag42)
                    {
                        this.dk1jg = string.Concat(new object[]
                        {
                            this.dk1jg,
                            "迟到 ",
                            time - 10.0,
                            " 分钟"
                        });
                        this.write(i, this.dk1jglie, this.dk1jg, this.searchflag);
                        this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  " + this.dk1jg + "\r\n");
                        this.dgv_day.Rows[this.rownum].Cells[7].Value = time - 10.0;
                        //this.dgv_day.Rows[this.rownum].Cells[7].Style.BackColor = Color.Yellow;
                        this.changeflag = true;
                    }
                }
                bool flag43 = time > 10.0;
                if (flag43)
                {
                    bool flag44 = (this.dk2jg == "外出" || this.dk2jg == "请假") && this.dk1jg != "外出" && this.dk1jg != "请假";
                    if (flag44)
                    {
                        this.dk2jg = string.Concat(new object[]
                        {
                            this.dk2jg,
                            " 早退 ",
                            time - 10.0,
                            " 分钟"
                        });
                        this.write(i, this.dk2jglie, this.dk2jg, this.searchflag);
                        this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  " + this.dk2jg + "\r\n");
                        this.dgv_day.Rows[this.rownum].Cells[8].Value = time - 10.0;
                        //this.dgv_day.Rows[this.rownum].Cells[8].Style.BackColor = Color.Yellow;
                        this.changeflag = true;
                    }
                }
            }
        }

        #endregion
        private int gzjblie;

        private int xxjblie;

        private int jjjblie;
        #region 加班时长验证
        public void jbtest(int i)
        {
            double spt = 0.0;
            if ((dk1jg == "出差" || dk1jg == "外出") && (dk2jg == "出差" || dk2jg == "外出"))
            {
                dkf = "08:00";
            }
            bool flag = this.dkl != "" && this.dkf != "";

            this.jbsc = this.datetemp(i).Item5;
            bool flag5 = double.Parse(jbsc) != 0.0;
            if (flag)
            {
                bool yb = false;
                string shp = this.sptemp1(this.shenpi).Item1;
                string shp2 = this.sptemp1(this.shenpi).Item2;
                string shp3 = this.sptemp1(this.shenpi).Item3;
                if ((shenpi.Contains("2小时")|| shenpi.Contains("4小时"))&&shenpi.Contains("加班") && banci.Contains("晚白班班次")&&
                    (xingqi.Contains("22-07-14")|| xingqi.Contains("22-07-15")))
                {
                    jbsc = shenpi.Contains("2小时") ? "2.0" : "4.0";
                    this.changeflag = true;
                    this.dgvwrite(this.rownum, 10, this.jbsc, this.dgv_day, Color.Yellow);
                    this.textBox1.AppendText(string.Concat(new string[]
                    {
                                string.Format("{0:D2}", this.rownum + 1),
                                "号  :  加班 ",
                                "0",
                                " 改为 ",
                                this.jbsc,
                                "\r\n"
                    }));
                    this.write(i, this.jbsclie, this.jbsc, this.searchflag);
                    this.write(i, this.gzjblie, this.jbsc, this.searchflag);
                    bool flag21 = this.Istx(i);
                    if (flag21)
                    {
                        this.dgvwrite(this.rownum, 6, this.jbsc, this.dgv_day, Color.Yellow);
                    }
                }
                bool flag2 = shp.Contains("加班");
                if (flag2)
                {
                    string spsc = this.sptemp2(shp).Item7;
                    if (double.Parse(spsc) > spt)
                    {
                        spt = double.Parse(spsc);
                    }
                }
                bool flag3 = shp2.Contains("加班");
                if (flag3)
                {
                    string spsc = this.sptemp2(shp2).Item7;
                    if (double.Parse(spsc) > spt)
                    {
                        spt = double.Parse(spsc);
                    }
                }
                bool flag4 = shp3.Contains("加班");
                if (flag4)
                {
                    string spsc = this.sptemp2(shp3).Item7;
                    if (double.Parse(spsc) > spt)
                    {
                        spt = double.Parse(spsc);
                    }
                }

                // bool flag1 = this.name != GetDATE(day_row + 1, xmlie) && banci.Contains("次日");

                if (flag5 || banci.Contains("休息"))
                {
                    bool flag6 = this.dkl.Contains("次日");
                    double dkh;
                    if (flag6)
                    {
                        this.dkls = this.dkl.Substring(3, 5);
                        dkh = this.timetemp(this.dkls).Item1;
                        //bool flag7 = this.banci.Contains("休息");
                        if (!banci.Contains("次日"))
                        {
                            dkh += 24.0;
                        }
                    }
                    else
                    {
                        this.dkls = this.dkl;
                        dkh = this.timetemp(this.dkls).Item1;
                    }
                    double dkm = this.timetemp(this.dkls).Item2;

                    bool flag8 = this.banci.Contains("班") && !banci.Contains("未排班");
                    if (flag8)
                    {
                        //bool flag9 = this.banci.Contains("次日");
                        double xbh;
                        double xbm;
                        //if (flag9)
                        //{
                        //    string sp = GetDATE(day_row + 1, splie);
                        //    if (!sp.Contains("加班") && this.name == GetDATE(day_row + 1, xmlie))
                        //    {
                        //        return;
                        //    }
                        //    xbh = 3.0;
                        //    if (banci.Contains("20:30"))
                        //    {
                        //        xbh = 4.0;
                        //    }

                        //    xbm = 30.0;
                        //}
                        //else
                        //{
                        //if (!this.shenpi.Contains("加班") && !banci.Contains("夜班"))
                        //{
                        //    return;
                        //}
                        string xbsj = this.banci.Substring(this.banci.Length - 5, 5);
                            xbh = this.timetemp(xbsj).Item1;
                            xbm = this.timetemp(xbsj).Item2;
                        //}
                        double jbm = (dkm - xbm) / 60.0;
                        double jb = dkh - xbh + jbm;
                        int jbint = (int)jb;
                        bool flag10 = jb - (double)jbint >= 0.5;
                        if (flag10)
                        {
                            jb = (double)jbint + 0.5;
                        }
                        else
                        {
                            jb = (double)jbint;
                        }
                        bool flag11 = jb < 0.0;
                        if (flag11)
                        {
                            jb = 0.0;
                        }
                        bool flag12 = this.shenpi.Contains("08:00") && this.banci.Contains("08:00");
                        if (flag12)
                        {
                            bool flag13 = (shp.Contains("加班") && shp.Contains("08:00")) || (shp2.Contains("加班") && shp2.Contains("08:00")) || (shp3.Contains("加班") && shp3.Contains("08:00"));
                            if (flag13)
                            {
                                double dkfh = this.timetemp(this.dkf).Item1;
                                double dkfm = this.timetemp(this.dkf).Item2;
                                bool flag14 = dkfh < 8.0;
                                if (flag14)
                                {
                                    double jb2 = (dkfm - 0.0) / 60.0;
                                    jb2 = 8.0 - dkfh - jb2;
                                    int jb2int = (int)jb2;
                                    bool flag15 = jb2 - (double)jb2int >= 0.5;
                                    if (flag15)
                                    {
                                        jb2 = (double)jb2int + 0.5;
                                    }
                                    else
                                    {
                                        jb2 = (double)jb2int;
                                    }
                                    bool flag16 = jb2 > 0.5;
                                    if (flag16)
                                    {
                                        jb += jb2;
                                        jbint = (int)jb;
                                    }
                                }
                            }
                        }
                        if (banci.Contains("夜班"))
                        {
                            double dkfh = this.timetemp(this.dkf).Item1;
                            if (dkfh > 17 && dkfh < 24 && !banci.Contains("SMT夜班"))
                            {
                                jb -= 0.5;
                            }
                        }
                        else
                        {
                            //jb = jb < spt ? jb : spt;
                        }
                        bool flag17 = jb != double.Parse(this.jbsc);
                        if (flag17)
                        {
                            string str = this.jbsc;
                            if (jb < double.Parse(this.jbsc) || double.Parse(this.jbsc) == 0)
                            {
                                this.jbsc = jb.ToString();
                            }
                            bool flag19 = jb < 0.0;
                            if (flag19)
                            {
                                this.jbsc = " 0";
                            }
                            bool flag20 = double.Parse(this.jbsc) != double.Parse(str);
                            if (flag20)
                            {
                                this.changeflag = true;
                                this.dgvwrite(this.rownum, 10, this.jbsc, this.dgv_day, Color.Yellow);
                                this.textBox1.AppendText(string.Concat(new string[]
                                {
                                    string.Format("{0:D2}", this.rownum + 1),
                                    "号  :  加班 ",
                                    str,
                                    " 改为 ",
                                    this.jbsc,
                                    "\r\n"
                                }));
                                this.write(i, this.jbsclie, this.jbsc, this.searchflag);
                            }
                        }
                        bool flag21 = !this.Istx(i);
                        if (flag21)
                        {
                            string gzjb = this.GetDATE(i, this.gzjblie).ToString();
                            if (gzjb == "")
                            {
                                gzjb = "0";
                            }
                            bool flag22 = double.Parse(this.jbsc) != double.Parse(gzjb);
                            if (flag22)
                            {
                                if (jb < double.Parse(this.jbsc) || double.Parse(this.jbsc) == 0)
                                {
                                    this.jbsc = jb.ToString();
                                }
                                bool flag24 = jb < 0.0;
                                if (flag24)
                                {
                                    this.jbsc = " 0";
                                }
                                this.write(i, this.gzjblie, this.jbsc, this.searchflag);
                            }
                        }
                        else
                        {
                            string gztx = this.GetDATE(i, this.gztxlie).ToString();
                            if (gztx == "")
                            {
                                gztx = "0";
                            }
                            bool flag25 = double.Parse(this.jbsc) != double.Parse(gztx);
                            if (flag25)
                            {
                                if (jb < double.Parse(this.jbsc) || double.Parse(this.jbsc) == 0)
                                {
                                    this.jbsc = jb.ToString();
                                }
                                bool flag27 = jb < 0.0;
                                if (flag27)
                                {
                                    this.jbsc = " 0";
                                }
                                this.write(i, this.gztxlie, this.jbsc, this.searchflag);
                            }
                            this.dgvwrite(this.rownum, 6, this.jbsc, this.dgv_day, Color.Yellow);
                        }
                    }
                    else
                    {
                        bool flag28 = this.banci.Contains("休息");
                        if (flag28)
                        {
                            if (!this.shenpi.Contains("加班"))
                            {
                                return;
                            }
                            //bool flag29 = yb && this.name != this.datetemp(i + 1).Item4;
                            //if (flag29)
                            //{
                            //    this.cantgetyb = true;
                            //    this.changeflag = true;
                            //    this.set(i, 0, this.searchflag);
                            //    this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  无法获取夜班下班卡\r\n");
                            //    this.dgvwrite(this.rownum, 10, jbsc.ToString(), this.dgv_day, Color.Yellow);
                            //    return;
                            //}
                            double sbh = this.timetemp(this.dkf).Item1;
                            double sbm = this.timetemp(this.dkf).Item2;
                            if (sbh == 12)
                            {
                                sbh = 13;
                                sbm = 0;
                            }
                            double jbm = (dkm - sbm) / 60.0;
                            double jb = dkh - sbh + jbm;
                            int jbint2 = (int)jb;
                            bool flag30 = jb - (double)jbint2 >= 0.5;
                            if (flag30)
                            {
                                jb = (double)jbint2 + 0.5;
                            }
                            else
                            {
                                jb = (double)jbint2;
                            }
                            bool flag31 = sbh < 12.0 && dkh >= 13;
                            if (flag31)
                            {
                                bool flag32 = this.bumen.Contains("制造一课") || this.bumen.Contains("SMT") || bumen.Contains("IPQC");
                                if (!flag32)
                                {
                                    jb -= 1.0;
                                }
                            }
                            if (sbh > 17 && sbh < 24 && dkl.Contains("次日") && !bumen.Contains("制造一课")&&!this.bumen.Contains("SMT") && !bumen.Contains("IPQC"))
                            {
                                jb -= 0.5;
                            }
                            jb = jb < spt ? jb : spt;
                            bool flag33 = jb != double.Parse(this.jbsc);
                            if (flag33)
                            {
                                string str2 = this.jbsc;
                                if (jb < double.Parse(this.jbsc) || double.Parse(this.jbsc) == 0)
                                {
                                    this.jbsc = jb.ToString();
                                }
                                bool flag35 = jb < 0.0;
                                if (flag35)
                                {
                                    this.jbsc = " 0";
                                }
                                bool flag36 = double.Parse(this.jbsc) != double.Parse(str2);
                                if (flag36)
                                {
                                    this.changeflag = true;
                                    this.dgvwrite(this.rownum, 10, this.jbsc, this.dgv_day, Color.Yellow);
                                    this.textBox1.AppendText(string.Concat(new string[]
                                    {
                                        string.Format("{0:D2}", this.rownum + 1),
                                        "号  :  加班 ",
                                        str2,
                                        " 改为 ",
                                        this.jbsc,
                                        "\r\n"
                                    }));
                                    this.write(i, this.jbsclie, this.jbsc, this.searchflag);
                                }
                            }
                            bool flag37 = !this.Isjjr(this.jjrday, this.xingqi);
                            if (flag37)
                            {
                                bool flag38 = !this.Istx(i);
                                if (flag38)
                                {
                                    string xxjb = this.GetDATE(i, this.xxjblie).ToString();
                                    if (xxjb == "")
                                    {
                                        xxjb = "0";
                                    }
                                    bool flag39 = double.Parse(this.jbsc) != double.Parse(xxjb);
                                    if (flag39)
                                    {
                                        if (jb < double.Parse(this.jbsc) || double.Parse(this.jbsc) == 0)
                                        {
                                            this.jbsc = jb.ToString();
                                        }
                                        this.write(i, this.xxjblie, this.jbsc, this.searchflag);
                                    }
                                }
                                else
                                {
                                    string xxtx = this.GetDATE(i, this.xxtxlie).ToString();
                                    if (xxtx == "")
                                    {
                                        xxtx = "0";
                                    }
                                    bool flag41 = double.Parse(this.jbsc) != double.Parse(xxtx);
                                    if (flag41)
                                    {
                                        if (jb < double.Parse(this.jbsc) || double.Parse(this.jbsc) == 0)
                                        {
                                            this.jbsc = jb.ToString();
                                        }
                                        this.write(i, this.xxtxlie, this.jbsc, this.searchflag);
                                    }
                                    this.dgvwrite(this.rownum, 6, this.jbsc, this.dgv_day, Color.Yellow);
                                }
                            }
                            else
                            {
                                bool flag43 = !this.Istx(i);
                                if (flag43)
                                {
                                    string jjjb = this.GetDATE(i, this.jjjblie).ToString();
                                    if (jjjb == "")
                                    {
                                        jjjb = "0";
                                    }
                                    bool flag44 = double.Parse(this.jbsc) != double.Parse(jjjb);
                                    if (flag44)
                                    {
                                        if (jb < double.Parse(this.jbsc) || double.Parse(this.jbsc) == 0)
                                        {
                                            this.jbsc = jb.ToString();
                                        }
                                        this.write(i, this.jjjblie, this.jbsc, this.searchflag);
                                    }
                                }
                                else
                                {
                                    string jjtx = this.GetDATE(i, this.jjtxlie).ToString();
                                    if (jjtx == "")
                                    {
                                        jjtx = "0";
                                    }
                                    bool flag46 = double.Parse(this.jbsc) != double.Parse(jjtx);
                                    if (flag46)
                                    {
                                        if (jb < double.Parse(this.jbsc) || double.Parse(this.jbsc) == 0)
                                        {
                                            this.jbsc = jb.ToString();
                                        }
                                        this.write(i, this.jjtxlie, this.jbsc, this.searchflag);
                                    }
                                    this.dgvwrite(this.rownum, 6, this.jbsc, this.dgv_day, Color.Yellow);
                                }
                            }
                        }
                    }
                    //if (double.Parse(this.jbsc) %1!=0)
                    //{
                    //    double a = double.Parse(this.jbsc) - (double)((int)double.Parse(this.jbsc));
                    //    bool flag49 = a != 0.5;
                    //    if (flag49)
                    //    {
                    //        this.changeflag = true;
                    //        this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  加班 " + this.jbsc + " 改为 ");
                    //        bool flag50 = a < 0.5;
                    //        if (flag50)
                    //        {
                    //            this.jbsc = ((int)double.Parse(this.jbsc)).ToString();
                    //        }
                    //        else
                    //        {
                    //            this.jbsc = ((int)double.Parse(this.jbsc) + 1).ToString();
                    //        }
                    //        this.dgvwrite(this.rownum, 10, this.jbsc.ToString(), this.dgv_day, Color.Yellow);
                    //        this.textBox1.AppendText(this.jbsc + "\r\n");
                    //        this.write(i, this.jbsclie, this.jbsc, this.searchflag);
                    //        bool flag51 = this.banci.Contains("休息");
                    //        if (flag51)
                    //        {
                    //            bool flag52 = !this.Isjjr(this.jjrday, this.xingqi);
                    //            if (flag52)
                    //            {
                    //                bool flag53 = !this.Istx(i);
                    //                if (flag53)
                    //                {
                    //                    this.write(i, this.xxjblie, this.jbsc, this.searchflag);
                    //                }
                    //                else
                    //                {
                    //                    this.dgvwrite(this.rownum, 6, this.jbsc, this.dgv_day, Color.Yellow);
                    //                    this.write(i, this.xxtxlie, this.jbsc, this.searchflag);
                    //                }
                    //            }
                    //            else
                    //            {
                    //                bool flag54 = !this.Istx(i);
                    //                if (flag54)
                    //                {
                    //                    this.write(i, this.jjjblie, this.jbsc, this.searchflag);
                    //                }
                    //                else
                    //                {
                    //                    this.dgvwrite(this.rownum, 6, this.jbsc, this.dgv_day, Color.Yellow);
                    //                    this.write(i, this.jjtxlie, this.jbsc, this.searchflag);
                    //                }
                    //            }
                    //        }
                    //        else
                    //        {
                    //            bool flag55 = !this.Istx(i);
                    //            if (flag55)
                    //            {
                    //                this.write(i, this.gzjblie, this.jbsc, this.searchflag);
                    //            }
                    //            else
                    //            {
                    //                this.dgvwrite(this.rownum, 6, this.jbsc, this.dgv_day, Color.Yellow);
                    //                this.write(i, this.gztxlie, this.jbsc, this.searchflag);
                    //            }
                    //        }
                    //    }
                    //}
                }
                //else
                //{
                //    this.changeflag = true;
                //    this.dgvwrite(this.rownum, 10, "0", this.dgv_day, Color.Yellow);
                //    this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  加班缺卡 " + this.jbsc + " 改为 0\r\n");
                //}
            }
            else if (flag5)
            {
                this.changeflag = true;
                this.dgvwrite(this.rownum, 10, "0", this.dgv_day, Color.Yellow);
                this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  加班缺卡 " + this.jbsc + " 改为 0\r\n");
            }
        }

        #endregion

        #region 夜班情况
        public void ybtemp(int i)
        {
            //bool flag = !this.banci.Contains("休息");
            //if (flag)
            //{
            //    string eb = this.GetDATE(this.day_row, this.yblie1);
            //    string sb = this.GetDATE(this.day_row, this.yblie2);
            //    bool flag2 = eb != "";
            //    if (flag2)
            //    {
            //        this.dgv_day.Rows[this.rownum].Cells[11].Value = "二班";
            //    }
            //    bool flag3 = sb != "";
            //    if (flag3)
            //    {
            //        this.dgv_day.Rows[this.rownum].Cells[11].Value = "三班";
            //    }
            //}
            //bool flag4 = this.banci.Contains("休息");
            //if (flag4)
            //{
                bool flag5 = this.dkl.Length > 3 && this.dkf != "";
                if (flag5)
                {
                    bool flag6 = this.dkl.Contains("次日");
                    if (flag6)
                    {
                        this.dkls = this.dkl.Substring(3, 5);
                        double dkh = this.timetemp(this.dkls).Item1;
                        double dkm = this.timetemp(this.dkls).Item2;
                        bool flag7 = (dkh == 0.0 && dkm >= 30.0) || dkh == 1.0 || dkh == 2.0 || (dkh == 3.0 && dkm <30.0);
                        if (flag7)
                        {
                            this.dgvwrite(this.rownum, 11, "二班", this.dgv_day, Color.Yellow);
                            this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  夜班 二班 \r\n");
                            this.write(i, this.yblie1, "1", this.searchflag);
                        }
                        bool flag8 = (dkh == 3.0 && dkm >= 30.0) || dkh >= 4.0;
                        if (flag8)
                        {
                            this.dgvwrite(this.rownum, 11, "三班", this.dgv_day, Color.Yellow);
                            this.changeflag = true;
                            this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  夜班 三班 \r\n");
                            this.write(i, this.yblie2, "1", this.searchflag);
                        }
                    }
                }
            //}
        }
        #endregion

        #region 旷工处理
        public void kgtest(int i)
        {
            bool flag = this.banci.Contains("不在考勤组") || this.lastdk;
            if (flag)
            {
                bool flag2 = this.kgts == "1";
                if (flag2)
                {
                    bool flag3 = this.dgv_day.Rows[this.rownum].Cells[2].Value.ToString() != "";
                    if (flag3)
                    {
                        this.dgvwrite(this.rownum, 2, "", this.dgv_day, Color.Yellow);
                    }
                    bool flag4 = this.dgv_day.Rows[this.rownum].Cells[3].Value.ToString() != "";
                    if (flag4)
                    {
                        this.dgvwrite(this.rownum, 3, "", this.dgv_day, Color.Yellow);
                    }
                    this.dgvwrite(this.rownum, 9, "", this.dgv_day, Color.Yellow);
                    this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  旷工 " + this.kgts + " 清空\r\n");
                    this.write(i, this.kgtslie, "", this.searchflag);
                    this.write(i, this.dk1jglie, "", this.searchflag);
                    this.write(i, this.dk2jglie, "", this.searchflag);
                    this.changeflag = true;
                }
                bool flag5 = this.qjsc != "";
                if (flag5)
                {
                    this.dgv_day.Rows[this.rownum].Cells[5].Value = "";
                    this.write(i, this.sjlie, "", this.searchflag);
                    this.write(i, this.bjlie, "", this.searchflag);
                    this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  辞职 清空请假\r\n");
                }
                bool flag6 = this.dk2jg == "缺卡" && this.name.Contains("离职");
                if (flag6)
                {
                    bool flag7 = this.dgv_day.Rows[this.rownum].Cells[2].Value.ToString() != "";
                    if (flag7)
                    {
                        this.dgvwrite(this.rownum, 2, "", this.dgv_day, Color.Yellow);
                    }
                    bool flag8 = this.dgv_day.Rows[this.rownum].Cells[3].Value.ToString() != "";
                    if (flag8)
                    {
                        this.dgvwrite(this.rownum, 3, "", this.dgv_day, Color.Yellow);
                    }
                    this.textBox1.AppendText(string.Format("{0:D2}", this.rownum + 1) + "号  :  辞职 清空打卡\r\n");
                    this.write(i, this.dk2jglie, "", this.searchflag);
                    this.changeflag = true;
                }
            }
        }
        #endregion

        #endregion

        #region 计时
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (timestartflag==true)
            {
                string hour = "";
                string min = "";
                s = s + 1;
                if (s == 60)
                {
                    m = m + 1;
                    s = 0;
                }
                if (m == 60)
                {
                    h = h + 1;
                    m = 0;
                }
                if (h != 0)
                {
                    hour = h + "小时";
                }
                if (m != 0)
                {
                    min = m + "分钟";
                }
                label1.Enabled = true;
                label1.Text = "已用时： " + hour + min + s + "秒";
            }
        }
        #endregion
    }
}
